![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
|
Hi, I would like to run a jvascript, checking if the radio button is checked. My radio button looks like: input type="radio" name="owned_business" value="yes" |
|
and i would like to check it with this: alert (document.myform.owned_business.checked); if (document.myform.owned_business.checked == false) but alert returns me "undefined" and i don't understand why, |
|
my form name is "myform" and the name of the radio is "owned_business" so i'm not seeing where i go wrong. Can anyone help me? |
#2
| |||
| |||
|
|
Radio buttons are expected to be in sets (all with the same name) and operate in a way that guarantees that at least one of them is always checked. |
|
An single input element that is expected to have one of two boolean states is best represented with a 'checkbox' element. |
#3
| |||
| |||
|
|
There is no requirement that one of them be selected initially, and it can be appropriate to require a nominally-conscious choice rather than providing a default. |
#4
| |||
| |||
|
|
Since there is typically no way to unselect a radio button group so that no options are checked, providing a default state that cannot be returned to is bad design. All radio button groups should have a default selected option. |
#5
| |||
| |||
|
|
Matt Kruse wrote on 03 jan 2008 in comp.lang.javascript: Since there is typically no way to unselect a radio button group so that no options are checked, providing a default state that cannot be returned to is bad design. |
|
All radio button groups should have a default selected option. Why? |
#6
| |||
| |||
|
|
Evertjan. wrote on 03 jan 2008 in comp.lang.javascript: Matt Kruse wrote on 03 jan 2008 in comp.lang.javascript: Since there is typically |
|
form input type=radio name=r value = '1' input type=radio name=r value = '2' /form button onclick='deselect();'>Deselect</button script type='text/javascript' function deselect(){ var r = document.forms[0].elements['r']; r[0].checked = ''; r[1].checked = ''; }; /script |
#7
| |||
| |||
|
|
Evertjan. said: Evertjan. wrote on 03 jan 2008 in comp.lang.javascript: Matt Kruse wrote on 03 jan 2008 in comp.lang.javascript: Since there is typically Typically. Did you see that, E? no way to unselect a radio button [snip] |
|
form input type=radio name=r value = '1' input type=radio name=r value = '2' /form button onclick='deselect();'>Deselect</button script type='text/javascript' function deselect(){ var r = document.forms[0].elements['r']; r[0].checked = ''; r[1].checked = ''; }; /script Well, I'd say that you don't want radio buttons, you want round checkboxes. And if that's what you want, make them behave that way, and let someone click to clear them, rather than providing an extra input people are not used to and will be confused by. |
#8
| |||
| |||
|
|
I don't, Anthony, it is the OP that wants something. Please address your comments to the right poster. |
#9
| |||
| |||
|
|
It comes very handy sometimes, like asking for m/f sex. Should we add a default radio button named "yet unknown", that is programmaticly disallowed to return to? |
#10
| |||
| |||
|
|
Evertjan. wrote: It comes very handy sometimes, like asking for m/f sex. Should we add a default radio button named "yet unknown", that is programmaticly disallowed to return to? The M/F choice is a very interesting one. If you have just the two buttons, with neither selected initially then you risk annoying the user considerably. They may not wish to divulge their sex, but if they accidentally click one of the the buttons they are left with the unpalatable choice between divulging the truth or lying. Many people will simply abandon your page at this point, so you lose. To avoid this on my survey websites, I always add the extra button "I prefer not to say" although (where I know my audience well) I sometimes label the third choice "Not in living memory" in order to raise a smile. |
![]() |
| Thread Tools | |
| Display Modes | |
| |