SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Wizard jumpthru's Avatar
    Join Date
    Apr 2000
    Location
    Los Angeles, California
    Posts
    1,008
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Clear all selected radio buttons?

    If you have a set of radio buttons, and you have set none of them to checked (so when the page opens, none are checked), and a user clicks one of them, but then decides he didn't want to click it, is there a way to make a link using javascript that sets them all back to unchecked?

    Thanks.

  2. #2
    Spam Can Kill!!! Disk-t's Avatar
    Join Date
    Jul 2001
    Location
    n/a
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <input type="button" value="clear" onClick="document.former.checkbutton1.checked=false">

  3. #3
    Spam Can Kill!!! Disk-t's Avatar
    Join Date
    Jul 2001
    Location
    n/a
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is an example:

    <form name="former">
    <p>checkbutton1<input type="radio" name="checkbutton1" onClick="document.former.checkbutton2.checked=false">
    </p>
    <p>checkbutton2<input type="radio" name="checkbutton2" onClick="document.former.checkbutton1.checked=false">
    </p>
    <p>
    <input type="button" value="clear" onClick="document.former.checkbutton1.checked=false;document.former.checkbutton2.checked=false">
    </form>
    </p>

  4. #4
    SitePoint Wizard jumpthru's Avatar
    Join Date
    Apr 2000
    Location
    Los Angeles, California
    Posts
    1,008
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oops, I am using radio buttons. How do you do this for radio buttons?

  5. #5
    Spam Can Kill!!! Disk-t's Avatar
    Join Date
    Jul 2001
    Location
    n/a
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Those are radio button. I just "named" them checkbutton1 and 2. Try running the script to see if this is what you want.

  6. #6
    JavaScript Guru (Big Ego) Arielladog's Avatar
    Join Date
    Jul 1999
    Location
    SC, USA
    Posts
    390
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey,

    On JSCity forums, a similar question was asked. A generic function was created which allowed the user to click the radio button again to uncheck it. I think it's vey useful, and I think the webbrowsers should automatically allow this, but anyway, you can use it as a JavaScript on the pages you want it on.

    http://66.34.42.140/forums/showthrea...&threadid=9258

    aDog


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
  •