Click to See Complete Forum and Search --> : Radio buttons question


karayan
05-29-2003, 08:34 PM
This is driving me batty. I have some exclusive radio buttons:

<form name="myForm">
<input type="radio" name="myRadio" value="1" CHECKED>
<input type="radio" name="myRadio" value="2">
</form>

Now the Javascript codeling that wants to read the value of the clicked button, tries to access:

document.myForm.myRadio.value

This always returns undefined, no matter what button I click.

What am I doing wrong?

George

:confused:

Jona
05-29-2003, 08:55 PM
I'm not sure I understand your question. You should be able to access the value of the radio button in this manner:


<script type="text/javascript">
<!--
function getRadioValue(){
alert(document.myForm.myRadio.value);
}
//-->
</script></head>
<body onload="getRadioValue();">


Your function must be called onload or onClick of an element after the page has loaded, otherwise "document.myForm.myRadio" is null or not an object.

Jona

karayan
05-29-2003, 09:31 PM
Jona:

Yes, in fact it is called onClick of a button elsewhere in the same form. Basically, the user clicks one of the radio buttons and clicks "OK"

The document.myForm.myRadio.value is still undefined.

George

Jona
05-29-2003, 09:48 PM
Please post all of your code or a link to the page so that we can see what you have going. Make sure that your form is opened and ended with <form> and </form>.

Jona