"undefined" value for radio button???

N

Noozer

For some reason I am getting an undefined value on a radio button on my
form. You can see in the HTML snippet below that I am setting values on all
the buttons, and have the "No" button selected by default. Yet when I
finally submit the form the javascript shows the value for the radio button
as "undefined"

I know this is going to be a stupid mistake, but can anyone explain what I'm
doing wrong?

---HTML snippet---

<form action="doForm.asp" method="post" onsubmit="return Validate(this)"
name="form1">
<!--some other fields -->
<input type="radio" name="ReceiveCC_i" value="No" checked >No
<input type="radio" name="ReceiveCC_i" value="Yes" >Yes
<input type="submit" value=" Submit Form " name="SUBMIT">
</form>

---Javascript snippet---

function Validate(f) {
/*Alert shows "undefined' ??? */
alert (f.elements['ReceiveCC_i'].value);

/* If ReceiveCC is YES, we need to append email address to CC field
if ( f.elements['ReceiveCC_i'].value == "Yes" ) {
f.elements['CC'].value = f.elements['CC'].value + "; " +
f.elements['FROM'].value;
}
}
 
S

Steve Pugh

Noozer said:
For some reason I am getting an undefined value on a radio button on my
form. You can see in the HTML snippet below that I am setting values on all
the buttons, and have the "No" button selected by default. Yet when I
finally submit the form the javascript shows the value for the radio button
as "undefined"

But what does doForm.asp show as the value when you take the
JavaScript out? i.e. what is actually being sent to the server?
I know this is going to be a stupid mistake, but can anyone explain what I'm
doing wrong?

<form action="doForm.asp" method="post" onsubmit="return Validate(this)"
name="form1">
<!--some other fields -->
<input type="radio" name="ReceiveCC_i" value="No" checked >No
<input type="radio" name="ReceiveCC_i" value="Yes" >Yes
<input type="submit" value=" Submit Form " name="SUBMIT">
</form>

function Validate(f) {
/*Alert shows "undefined' ??? */
alert (f.elements['ReceiveCC_i'].value);

RecieveCC_i doesn't have a value.
RecieveCC_i is an array of the individual radio buttons. You need to
find which one is selected and then find the value for that one.

Steve
 
N

Noozer

For some reason I am getting an undefined value on a radio button on my
But what does doForm.asp show as the value when you take the
JavaScript out? i.e. what is actually being sent to the server?

RecieveCC_i doesn't have a value.
RecieveCC_i is an array of the individual radio buttons. You need to
find which one is selected and then find the value for that one.

Thanks... I've changed the code to:
if ( f.elements['ReceiveCC_i'][1].checked ) {
and it works. I could have sworn that I'd used the VALUE property before
though.

Just wondering now if there was a way to use something like
"f.elements['ReceiveCC_i']['Yes''].checked"

Thanks!!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top