SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2002
    Location
    Birmingham UK
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Radios and Checkboxes

    On a search form, I've got two radio options. One "Search All" and another "Search Category".
    After this, I have checkboxes of all the categories.

    How do I get the radio options to change if one of the categories is chosen?

    My form is like the following:

    <form name=form1>
    <input type="radio" name="SL" value="1"> All
    <input type="radio" name="SL" value="2"> Categories
    <input type="checkbox" name="ListID" value="1"> Cat 1
    <input type="checkbox" name="ListID" value="2"> Cat 2
    <input type="checkbox" name="ListID" value="3"> Cat 3
    </form>

    Any ideas?

    Cheers

  2. #2
    SitePoint Evangelist
    Join Date
    Jan 2002
    Posts
    420
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    var payment;
    var i;
    var theOption;
    for (i = 0; i <= 2; i++){
    theOption = document.appForm.payType[i];
    if (theOption.checked == true){
    payment = theOption.value;
    }
    }

    use this code to grab the value from radio buttons, youll have to change it to meet your needs.

    dont have time to help right now but ill try to get on later to help out if you dont understand
    Wavelan

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2002
    Location
    Birmingham UK
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cheers for the help...

    ... but I don't quite get the code you've put down.

    I know I've not quite got the form right (four check boxes with the same name), but I don't quite get how I put that code into my example.

    If you could expand on what you're saying a little (when you've got the chance) I would be grateful.

    Thanks
    Si

  4. #4
    ********* Genius Mike's Avatar
    Join Date
    Apr 2001
    Location
    Canada
    Posts
    5,458
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Re: Radios and Checkboxes

    Originally posted by simey_j
    How do I get the radio options to change if one of the categories is chosen?
    Do you mean you want the VALUE to change, or the text? Or do you just want the form to use only the options selected?
    Mike
    It's not who I am underneath, but what I do that defines me.

  5. #5
    SitePoint Evangelist
    Join Date
    Jan 2002
    Posts
    420
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    First of all the Avs are going down Mike

    Now what did you want to do exactly take the value from radio buttons or checkboxes?
    Wavelan

  6. #6
    SitePoint Enthusiast
    Join Date
    Feb 2002
    Location
    Birmingham UK
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Basically, if you click on one of the categories (one of the checkboxes) I want the radio option to change to Category rather than be All.

    (there are two options, all or category)

    Any more thoughts?

  7. #7
    SitePoint Zealot Drew630's Avatar
    Join Date
    Nov 2001
    Location
    Maryland
    Posts
    175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This should work for you.

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    
    <html>
    <head>
    	<title>Untitled</title>
    <script language="javascript">
    function getOption(caller) {
      if (caller == "check") {
      	 document.form1.SL[1].checked = true;
      }
      else if (caller == "all") {
      	 for (i = 0; i < 3; i++) {
       	 	 document.form1.ListID[i].checked = false;
         }	
      }
    }
    </script>
    </head>
    
    <body>
    <form name="form1"> 
    <input type="radio" name="SL" value="1" onclick = "getOption('all')"> All 
    <input type="radio" name="SL" value="2"> Categories 
    <input type="checkbox" name="ListID" value="1" onClick = "getOption('check');"> Cat 1 
    <input type="checkbox" name="ListID" value="2" onClick = "getOption('check');"> Cat 2 
    <input type="checkbox" name="ListID" value="3" onClick = "getOption('check');"> Cat 3 
    </form> 
    
    
    </body>
    </html>

    Drew
    ~Drew

    There Is No Greater Joy Than Soaring High On The Wings Of Your Dreams, Except Maybe The Joy Of Watching A Dreamer Who Has Nowhere To Land But In The Ocean Of Reality.

  8. #8
    ********* Genius Mike's Avatar
    Join Date
    Apr 2001
    Location
    Canada
    Posts
    5,458
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    The Avs are going all the way. Van should take some notes
    Mike
    It's not who I am underneath, but what I do that defines me.


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
  •