[Javascript] Javascript - Form value undefined
Tim Makins
spindrift at oceanfree.net
Tue Nov 11 01:21:59 CST 2003
----- Original Message -----
From: "Tim Burgan" <lists.latech.edu at greaterthani.com>
To: "[JavaScript List]" <javascript at LaTech.edu>
Sent: Tuesday, November 11, 2003 7:04 AM
Subject: [Javascript] Javascript - Form value undefined
> <http://www.greaterthani.com/05_programming/week5help.htm>
>
> The form with the radio button displays a result of 'undefined', when it
> should be either 0 or 0.25
>
> Can someone please take a look at this to kelp me out?
Always happy to kelp out if I can !
You can't read radio values like that. You must see if they are checked or
not first.
Look at the script below (not mine)
Tim in Ireland.
<html>
<head>
<title>Listing 28.7. Finding the Activated Radio Button In a Group</title>
<script language="JavaScript" type="text/javascript">
<!--
function radio_active(radio_group) {
// Run through the group
for (counter = 0; counter < radio_group.length; counter++) {
// When we find the activated button, return the index
if (radio_group[counter].checked) {
return counter
}
}
// If no button is activated, return -1
return -1
}
function display_radio_value(current_form) {
// Get the index of the activated button
var radio_index = radio_active(current_form.freight_group)
// If a button is activated, display its value in the text box
if (radio_index >= 0) {
current_form.selected_radio.value =
current_form.freight_group[radio_index].value
}
}
//-->
</script>
</head>
<body>
<form>
<input type="radio" name="freight_group" value="FedEx" checked>Federal
Express
<br>
<input type="radio" name="freight_group" value="UPS">United Parcel Service
<br>
<input type="radio" name="freight_group" value="Airborne">Airborne Express
<br>
<input type="radio" name="freight_group" value="Mail">Surface Mail
<br>
<input type="text" name="selected_radio">
<br>
<input type="button" value="Display Active Radio Value"
onClick="display_radio_value(this.form)">
</form>
</body>
</html>
More information about the Javascript
mailing list