PDA

View Full Version : OnClick Radio button value


BrianMerkel
06-27-2006, 01:07 PM
Hello, I am trying to extract the value of a selected radio button. Here is what I have:


<head>
<SCRIPT TYPE="text/javascript">
<!--
function change(changer)
{
changer.Change.value = "????"
}
//-->
</SCRIPT>
</head>
<body>
<form>
<INPUT type="radio" name="number" "value="5"> 5
<BR>
<INPUT type="radio" name="number" "value="10"> 10
<BR>
<INPUT type="radio" name="number" "value="15"> 15
<br>
Number Selected: <input type="text" name="Change" value="">

<input type="button" name="Changebutton" onclick="change(this.form)" value="Change">

</form>
</body>



Where you see "????" what am I supposed to put to gather which radio button the user has selected?

If anyone could help, that would be great!

Thanks alot!

Geoserv
06-27-2006, 01:18 PM
You could try:

Javascript:
<script language="JavaScript">
<!--
function radio_button_checker()
{
// set var radio_choice to false
var radio_choice = false;

// Loop from zero to the one minus the number of radio button selections
for (counter = 0; counter < radio_form.radio_button.length; counter++)
{
// If a radio button has been selected it will return true
// (If not it will return false)
if (radio_form.radio_button[counter].checked)
radio_choice = true;
}

if (!radio_choice)
{
// If there were no selections made display an alert box
alert("Please select a letter.")
return (false);
}
return (true);
}

-->
</script>


html:

<form method="get" action="whatever"
onsubmit="return radio_button_checker()" name="radio_form">
<input type="radio" value="A" name="radio_button">A
<br>
<input type="radio" value="B" name="radio_button">B
<br>
<input type="radio" value="C" name="radio_button">C
<br>
<input type="radio" value="D" name="radio_button">D
<br>
<input type="submit" value="Submit">
</form>


See if that works.

Geoserv.

BrianMerkel
06-27-2006, 01:30 PM
That is not what im trying to do. All I want to do is post the value of the selected radio button into the text box.