Answers
Feb 16, 2007 - 03:58 AM
The way to select a radiobutton from within JavaScript is by iterating through the array that is created automatically when JavaScript encounters a radiobutton or checkbox type of input.
function setRadio()
{
var rad = document.getElementById(radiobutton);
for (i = 0; i < rad.length; i++)
{
// Perform appropriate test and then use
if (whatever)
{
rad[i].checked = true;
}
}
}
That should check the radio button you're expecting.
I hope this helps,
Ric
Feb 16, 2007 - 04:34 AM
That works!
Actually I just needed this part:
buttonElement.checked = true
...as I already knew (by Id) which button I wanted to select.
You've answered my question, but I was wondering about your example... it seems to rely on document.getElementById to return an array... Is that correct?
Well, thanks anyway, i'll give you the points.
Jakob
Mar 18, 2009 - 08:05 AM
Jan 23, 2020 - 12:43 AM
Try this.
if(gendd.contains("0"))
{
male.setChecked(true);
female.setChecked(false);
}
else
{
male.setChecked(false);
female.setChecked(true);
}
Ruskin | AdminCloudDesktopOnline
Add New Comment