SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast mtran's Avatar
    Join Date
    Apr 2006
    Location
    San Jose, US
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Simple function not working

    Hi, could you help tell me why my simple function doesn't work here? Not well versed in javascript as you can tell.

    Code:
    <script type="text/javascript">
    function gts_part(id1,id2,id3){
      if (document.getElementById(id1).checked == true)  {
        document.getElementById(id2).disabled = false;
        document.getElementById(id3).disabled = false;}
      else	
        document.getElementById(id2).disabled = true;
        document.getElementById(id3).disabled = true;
       document.getElementById(id2).checked = false;
        document.getElementById(id3).checked = false;	}
    }
    </script>
    
    <input type="checkbox" name="survey" value="gts" id="s1" onclick="gts_part(s1,s2,s3);" /> Commit to Participate<br />
    <input type="radio" name="gts_global" value="global" id="s2" disabled /> Global<br />
    <input type="radio" name="gts_global" value="us" id="s3" disabled /> US Only<br />
    It works ok if I used the individual field ids as in here:

    Code:
    <script type="text/javascript">
    function gss_part(){
      if (document.getElementById("x1").checked == true)  {
        document.getElementById("x2").disabled = false;
        document.getElementById("x3").disabled = false;}
    	
      else{
        document.getElementById("x2").disabled = true;
        document.getElementById("x3").disabled = true;
        document.getElementById("x2").checked = false;
        document.getElementById("x3").checked = false;	
    }}
    </script>
    
    <input type="checkbox" name="survey1" value="gts" id="x1" onclick="gss_part();" /> Commit to Participate<br />
    <input type="radio"  name="gts_global1" value="global" id="x2" disabled /> Global<br />
    <input type="radio"  name="gts_global1" value="us" id="x3" disabled /> US Only<br />

  2. #2
    SitePoint Member
    Join Date
    Nov 2009
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    shoudnt there be "{" after "else"?

  3. #3
    SitePoint Enthusiast mtran's Avatar
    Join Date
    Apr 2006
    Location
    San Jose, US
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That I missed, but even after adding the bracket after else, it's still not working.

    ------

    Actually I found the answer now.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •