SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Evangelist CyberFuture's Avatar
    Join Date
    May 2001
    Location
    San Diego, CA
    Posts
    434
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Radio Button Problem

    Is it possible to unclick a radio button?

    My boss says it is, and that he's seen it on plenty of sites. He has been unable to give me the name of one site. Does anybody know if its possible, and if so the name of a web site that demostrates it?


    Thanks,

  2. #2
    SitePoint Wizard Pedro Monteiro's Avatar
    Join Date
    Sep 2002
    Location
    Lisbon
    Posts
    1,393
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have seen a javascript that played arround with something similiar, I'll try to find it.

  3. #3
    SEOChat has too many ads Protoss's Avatar
    Join Date
    Aug 2004
    Location
    Long Island, NY
    Posts
    248
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, if the button isn't selected initially, a reset button that resets the whole form will do it. Otherwise, you would have to loop through the radio buttons and set their "checked" property to false.

    VERY rudimentary example:

    Code:
    <SCRIPT language="JavaScript">
    function UncheckIt() {
    	document.TestForm.TestRadio[0].checked=false;
    }
    </SCRIPT>
    <form name="TestForm">
    <input type="radio" name="TestRadio" value="Anything" checked> Anything<br>
    <input type="radio" name="TestRadio" value="Something"> Something<br>
    <input type="button" value="run for it marty" onclick="UncheckIt();">
    </form>
    If you wanted to get more complex you could dynamically loop through any radio buttons in the form, etc.

  4. #4
    SitePoint Evangelist CyberFuture's Avatar
    Join Date
    May 2001
    Location
    San Diego, CA
    Posts
    434
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't want to use the reset button. I don't want who ever is filling out the form to have to do it over again just because they change their mind.

  5. #5
    <? james('rules'); ?>
    Join Date
    Jun 2004
    Location
    Wales, UK
    Posts
    788
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could make a radio button, that initilizes a javascript code which sets all the values to unchecked?
    If knowledge is power - Why isn't our army librarians?!
    Statistics show that 63% of all statistics are fake.
    When i was little i broke my neck, and i havent looked back since .
    I completed the internet in 1 week. The end boss was pretty easy though .

  6. #6
    Non-Member Egor's Avatar
    Join Date
    Jan 2004
    Location
    Melbourne, Australia
    Posts
    7,305
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    While it may be possible, it's ridiculously pointless when you have check-boxes specifically made for that.

  7. #7
    SitePoint Evangelist CyberFuture's Avatar
    Join Date
    May 2001
    Location
    San Diego, CA
    Posts
    434
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Except checkboxes can't be restricted to one selection in a group.

  8. #8
    SitePoint Enthusiast mutus's Avatar
    Join Date
    Sep 2003
    Location
    NY, USA
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    checkboxes can be restricted to one (or any fixed number of) selection(s) also using javascript. It's just a lot of hassle... if you absolutely need radio buttons and the ability to clear them, I would use the button/loop solution outlined above.

    <edit>
    i thought a loop was already shown. here's a simple example:
    HTML Code:
    <script type="text/javascript">
    function doUncheck(ra)
    {
    var i, j;
    for(i = 0, j = ra.length; i < j; i++) ra[i].checked = false;
    }
    </script>
    <form name="frm">
    <input name="rad" type="radio" value="val1" /><br />
    <input name="rad" type="radio" value="val2" /><br />
    <input name="rad" type="radio" value="val3" /><br />
    <input name="rad" type="radio" value="val4" /><br />
    <input name="btnClear" type="button" value="clear radio choices" onclick="doUncheck(this.form.rad);" />
    </form>

  9. #9
    Non-Member Egor's Avatar
    Join Date
    Jan 2004
    Location
    Melbourne, Australia
    Posts
    7,305
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by CyberFuture
    Except checkboxes can't be restricted to one selection in a group.
    And that's where radio buttons come in.

  10. #10
    SitePoint Enthusiast mutus's Avatar
    Join Date
    Sep 2003
    Location
    NY, USA
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by mstwntd
    And that's where radio buttons come in.
    You seem to ignore what CyberFuture is asking for... which is a group of choices, of which only one may be selected at a time (feature of radios), where the user has ability to "uncheck" their choice (feature of check boxes).

    Neither radio buttons nor checkboxes alone will provide this functionality without some scripting.

  11. #11
    SitePoint Evangelist CyberFuture's Avatar
    Join Date
    May 2001
    Location
    San Diego, CA
    Posts
    434
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Everybody for your help. Happily, I've convinced my boss to take a different route. Though I REALLY wish radio buttons where unclickable.


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
  •