moswa
asked on
check radiobutton
I would like to check if one of my radiobuttons is checked.
By default, NONE of the radio-buttons must be pre-checked
Problem: with my currently script, it checkes which value is checked, BUT if none of the radio buttons is checked, it gives automatically the value of the first radio button.
<radio name=a1 value=1>
<radio name=a1 value=2>
<radio name=a1 value=3>
<radio name=a1 value=4>
<radio name=a1 value=5>
function getSelectedButton(buttonGr oup)
{
for (var i=0;i<buttonGroup.length;i ++)
{
if (buttonGroup[i].checked)
{
return i
}
}
return 0
}
var i=getSelectedButton(docume nt.form.a1 )
alert("You chose "+ form.a1[i].value + ".")
By default, NONE of the radio-buttons must be pre-checked
Problem: with my currently script, it checkes which value is checked, BUT if none of the radio buttons is checked, it gives automatically the value of the first radio button.
<radio name=a1 value=1>
<radio name=a1 value=2>
<radio name=a1 value=3>
<radio name=a1 value=4>
<radio name=a1 value=5>
function getSelectedButton(buttonGr
{
for (var i=0;i<buttonGroup.length;i
{
if (buttonGroup[i].checked)
{
return i
}
}
return 0
}
var i=getSelectedButton(docume
alert("You chose "+ form.a1[i].value + ".")
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
your function returns 0 :
function getSelectedButton(buttonGr oup){
for (var i=0;i<buttonGroup.length;i ++){
if (buttonGroup[i].checked) {
return i
}
}
// this statement makes it zero
return 0
}
u need to remove that part.... :^) third
function getSelectedButton(buttonGr
for (var i=0;i<buttonGroup.length;i
if (buttonGroup[i].checked) {
return i
}
}
// this statement makes it zero
return 0
}
u need to remove that part.... :^) third
ASKER
moswa