S
Steve Swift
I have a page containing:
<FORM NAME=radios>
<INPUT TYPE=RADIO NAME=RAD VALUE=1 ID=RAD1>
<LABEL FOR=RAD1>Check One</LABEL>
<A onClick="document.radios.RAD[0].checked=false; return false">Uncheck
One</A><BR>
<INPUT TYPE=RADIO NAME=RAD VALUE=2 ID=RAD2>
<LABEL FOR=RAD2>Check Two</LABEL><BR>
<DIV STYLE="display:none"><INPUT TYPE=RADIO NAME=RAD ID=RAD3></DIV>
<A onClick="document.radios.RAD[2].checked=true; return false">Select
Hidden</A><BR>
<BUTTON onclick="if (document.radios.RAD1.checked) {alert('Check one is
checked')} else {alert('Check one is not checked')}">Try Me!</BUTTON>
</FORM>
You can see this at the bottom of http://swiftys.org.uk/test.html
If you check one of the two visible buttons then click the "Try Me!"
button, then you get the expected alert, but the radio button is also
unchecked. Can anyone tell me why the radio button gets unchecked when
all I have done is refer to its checked attribute?
I know that adding "return false" to the end of the JavaScript on the
button stops the button getting unchecked, but I don't understand why it
should be necessary.
<FORM NAME=radios>
<INPUT TYPE=RADIO NAME=RAD VALUE=1 ID=RAD1>
<LABEL FOR=RAD1>Check One</LABEL>
<A onClick="document.radios.RAD[0].checked=false; return false">Uncheck
One</A><BR>
<INPUT TYPE=RADIO NAME=RAD VALUE=2 ID=RAD2>
<LABEL FOR=RAD2>Check Two</LABEL><BR>
<DIV STYLE="display:none"><INPUT TYPE=RADIO NAME=RAD ID=RAD3></DIV>
<A onClick="document.radios.RAD[2].checked=true; return false">Select
Hidden</A><BR>
<BUTTON onclick="if (document.radios.RAD1.checked) {alert('Check one is
checked')} else {alert('Check one is not checked')}">Try Me!</BUTTON>
</FORM>
You can see this at the bottom of http://swiftys.org.uk/test.html
If you check one of the two visible buttons then click the "Try Me!"
button, then you get the expected alert, but the radio button is also
unchecked. Can anyone tell me why the radio button gets unchecked when
all I have done is refer to its checked attribute?
I know that adding "return false" to the end of the JavaScript on the
button stops the button getting unchecked, but I don't understand why it
should be necessary.