
Originally Posted by
frrlod
Forgot to mention, it returns 'undefined' instead of the fruit value.
The value of a radio button group can be read by looping through the elements (you can research that). There is no need to use onclick events and setting the value of a radio button group is an illegal operation so cannot be expected to work.
The javascript: pseudo protocol should never be used, you can research why.
Here's a fix for your code that keeps the onclick events to set a hidden field:
Code:
<html>
<head>
<title></title>
<script type="text/javascript">
function FruitBox(f)
{
alert( f.response.value );
}
</script>
</head>
<body>
<form name="myform">
<input type='hidden' name='response'>
<input type="radio" name="fruit" onClick="this.form.response.value = 'oranges'">Oranges & Tangerines<br>
<input type="radio" name="fruit" onClick="this.form.response.value = 'bananas'">Bananas<br>
<input type="radio" name="fruit" onClick="this.form.response.value = 'peaches'">Peaches, Nectarines & Plums<br>
<input type="button" value="click here" onclick="FruitBox( this.form )">
</form>
</body>
</html>
Where used, return should be executed unconditionally and always as the last statement in the function.
That's my signature, it's not part of the damn post!
Bookmarks