L
Laser Lips
Hi All. This one has plagued me for a while.
I want to get the value of the selected radio button in 2 ways.
Bearing in mind that the radio buttons are always in a form tag.
1) I want to be able to get the value by using somthing like the
following...
myRadio = document.getElementById("myRadio");
//then somehow get the value of the selected radio button.
2) Have a function which is pased the form element and get to it that
way. eg.
function getVals(form)
{
myrad = form.myRadio
//then somehow get the value of the selected radio button.
}
=========================
Playing with other code i was able to get the value by doing the
following...
<HTML>
<HEAD>
<script>
function GO()
{
alert(rad.length);
for(x=0;x<rad.length;x++)
{
if(rad[x].checked==true)
{
alert(rad[x].value);
}
}
}
</script>
</HEAD>
<BODY>
<input type='radio' name='rad' id='rad' value='answer1'/>1
<input type='radio' name='rad' id='rad' value='answer2'/>2
<input type='radio' name='rad' id='rad' value='answer3'/>3
<input type='radio' name='rad' id='rad' value='answer4'/>4
<button onclick='GO();'>GO</button>
</BODY>
</HTML>
=========================
BUT I dont want to be able to just access the radio button direclty
because in some applications of this code, it doesnt work.
I really want to use document.getElementById and then continue from
that.
Any suggestions?
Graham
I want to get the value of the selected radio button in 2 ways.
Bearing in mind that the radio buttons are always in a form tag.
1) I want to be able to get the value by using somthing like the
following...
myRadio = document.getElementById("myRadio");
//then somehow get the value of the selected radio button.
2) Have a function which is pased the form element and get to it that
way. eg.
function getVals(form)
{
myrad = form.myRadio
//then somehow get the value of the selected radio button.
}
=========================
Playing with other code i was able to get the value by doing the
following...
<HTML>
<HEAD>
<script>
function GO()
{
alert(rad.length);
for(x=0;x<rad.length;x++)
{
if(rad[x].checked==true)
{
alert(rad[x].value);
}
}
}
</script>
</HEAD>
<BODY>
<input type='radio' name='rad' id='rad' value='answer1'/>1
<input type='radio' name='rad' id='rad' value='answer2'/>2
<input type='radio' name='rad' id='rad' value='answer3'/>3
<input type='radio' name='rad' id='rad' value='answer4'/>4
<button onclick='GO();'>GO</button>
</BODY>
</HTML>
=========================
BUT I dont want to be able to just access the radio button direclty
because in some applications of this code, it doesnt work.
I really want to use document.getElementById and then continue from
that.
Any suggestions?
Graham