M
mark4asp
I have a group of radio buttons:
<input type="radio" name="radioList" id="rad1" value="1" />1<br />
<input type="radio" name="radioList" id="rad2" value="2" />2<br />
<input type="radio" name="radioList" id="rad3" value="3" />3<br />
After one of them had been selected (with a mouse click) there seems no
way to clear the selection with javascript. i.e. To deselect.
For instance after I do this:
function clearAllRadios() {
var radList = document.getElementsByName('radioList');
for (var i = 0; i < radList.length; i++) {
if(radList.checked) radList.checked = false;
}
}
the display continues to show the previous element as selected - even
though its checked property has now been set to false.
Likewise.
document.forms[0].reset() has no effect upon the display.
At this point I added a fourth item:
<span style="display:none"><input type="radio" name="radioList"
id="rad4" value="4" /><span>
but I can't clear the display by setting its checked property to true:
document.getElementById('rad4').checked = true;
The same behavior is seen in Safari, IE6 and FF.
This is an asp.net page but the radios here are pure html. Setting the
page's ViewState to false didn't cure the problem.
Is this a general problem with radio lists in html forms?, is it
specific to asp.net?, or is it some private bug of mine ?
PS 1:
By adding an onclick event [onclick="ClearRad(this)"] to each button I
can, at least, deselect the currently selected display item:
var checkedRadio;
function ClearRd(oRad)
{
if (checkedRadio == oRad)
{
oRad.checked = false;
checkedRadio = null;
} else {
checkedRadio = oRad;
}
}
But that's not what I want.
PS 2:
Someone told me to use setAttribute(), but I tried it and it didn't
work. But isn't that IE6 only anyway?
<input type="radio" name="radioList" id="rad1" value="1" />1<br />
<input type="radio" name="radioList" id="rad2" value="2" />2<br />
<input type="radio" name="radioList" id="rad3" value="3" />3<br />
After one of them had been selected (with a mouse click) there seems no
way to clear the selection with javascript. i.e. To deselect.
For instance after I do this:
function clearAllRadios() {
var radList = document.getElementsByName('radioList');
for (var i = 0; i < radList.length; i++) {
if(radList.checked) radList.checked = false;
}
}
the display continues to show the previous element as selected - even
though its checked property has now been set to false.
Likewise.
document.forms[0].reset() has no effect upon the display.
At this point I added a fourth item:
<span style="display:none"><input type="radio" name="radioList"
id="rad4" value="4" /><span>
but I can't clear the display by setting its checked property to true:
document.getElementById('rad4').checked = true;
The same behavior is seen in Safari, IE6 and FF.
This is an asp.net page but the radios here are pure html. Setting the
page's ViewState to false didn't cure the problem.
Is this a general problem with radio lists in html forms?, is it
specific to asp.net?, or is it some private bug of mine ?
PS 1:
By adding an onclick event [onclick="ClearRad(this)"] to each button I
can, at least, deselect the currently selected display item:
var checkedRadio;
function ClearRd(oRad)
{
if (checkedRadio == oRad)
{
oRad.checked = false;
checkedRadio = null;
} else {
checkedRadio = oRad;
}
}
But that's not what I want.
PS 2:
Someone told me to use setAttribute(), but I tried it and it didn't
work. But isn't that IE6 only anyway?