467,225 Members | 1,368 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,225 developers. It's quick & easy.

radio box value is always undefined ?

I was working on this simple form with radio boxes.
And when I click on one of the radio box, it tell me the value is
"undefined"
Why is that ? I did defined the value of each radio box:

<input type=radio name='Usetax' value='basic'
onClick='document.myform.amount.value=document.myf orm.Usetax.value'>
<input type=radio name='Usetax' value='no'
onClick='document.myform.amount.value=document.myf orm.Usetax.value'>
<input type=radio name='Usetax' value='mytax'
onClick='document.myform.amount.value=document.myf orm.Usetax.value'>

Can anyone help ?

Thank a lot.

Eric
Here is the entire HTML:

<html>
<body>
<form name='myform' action='post'>
<input type=radio name='Usetax' value='basic'
onClick="document.forms[0].amount.value=document.myform.Usetax.value;
return(true);">

Default Tax

<input type=radio name='Usetax' value='no' checked
onClick="document.forms[0].amount.value=document.myform.Usetax.value;
return(true);">

No Tax

<input type=radio name='Usetax' value='mytax'
onClick="
document.forms[0].amount.value=document.myform.Usetax.value;
return(true);">
Other tax
<br>
Tax Amount: $<input type=text name=tax size=5 value=0.00><br>
total amount
<input type=text name=amount value="">
</form>

</body></html>
--

Jul 20 '05 #1
  • viewed: 11516
Share:
3 Replies
Eric,

Try this:-

<form name="myform">
<input type=radio name="Usetax" value="basic"
onClick="document.myform.amount.value=this.value;" >
<input type=radio name="Usetax" value="no"
onClick="document.myform.amount.value=this.value;" >
<input type=radio name="Usetax" value="mytax"
onClick="document.myform.amount.value=this.value;" >
<input type="text" name="amount">
</form>

Stu
"Eric Chang" <ec****@eatools.com> wrote in message
news:c8*******************@twister.socal.rr.com...
I was working on this simple form with radio boxes.
And when I click on one of the radio box, it tell me the value is
"undefined"
Why is that ? I did defined the value of each radio box:

<input type=radio name='Usetax' value='basic'
onClick='document.myform.amount.value=document.myf orm.Usetax.value'>
<input type=radio name='Usetax' value='no'
onClick='document.myform.amount.value=document.myf orm.Usetax.value'>
<input type=radio name='Usetax' value='mytax'
onClick='document.myform.amount.value=document.myf orm.Usetax.value'>

Can anyone help ?

Thank a lot.

Eric
Here is the entire HTML:

<html>
<body>
<form name='myform' action='post'>
<input type=radio name='Usetax' value='basic'
onClick="document.forms[0].amount.value=document.myform.Usetax.value;
return(true);">

Default Tax

<input type=radio name='Usetax' value='no' checked
onClick="document.forms[0].amount.value=document.myform.Usetax.value;
return(true);">

No Tax

<input type=radio name='Usetax' value='mytax'
onClick="
document.forms[0].amount.value=document.myform.Usetax.value;
return(true);">
Other tax
<br>
Tax Amount: $<input type=text name=tax size=5 value=0.00><br>
total amount
<input type=text name=amount value="">
</form>

</body></html>
--

Jul 20 '05 #2
"Eric Chang" <ec****@eatools.com> wrote in message news:<c8*******************@twister.socal.rr.com>. ..
I was working on this simple form with radio boxes.
And when I click on one of the radio box, it tell me the value is
"undefined"
Why is that ? I did defined the value of each radio box:

<input type=radio name='Usetax' value='basic'
onClick='document.myform.amount.value=document.myf orm.Usetax.value'>
<input type=radio name='Usetax' value='no'
onClick='document.myform.amount.value=document.myf orm.Usetax.value'>
<input type=radio name='Usetax' value='mytax'
onClick='document.myform.amount.value=document.myf orm.Usetax.value'>

Can anyone help ?

Thank a lot.

Eric


Hi

I think in the code you should use above in each of the 3 radio
buttons is:

onClick='document.myform.amount.value=this.value'

which will put the string 'basic', 'no' or 'mytax' into the amount
form element (assuming they're the values what you want in amount).

I think document.myform.Usetax doesn't have value because...
document.myform.Usetax is an array of the elements that share the name
'Usetax' so it is 3 radio buttons with 3 values:
document.myform.Usetax[0].value which is 'basic'
document.myform.Usetax[1].value which is 'no'
document.myform.Usetax[3].value which is 'mytax'
but it's nicer to use 'this.value' to get the value of the radio
button clicked.

Hope that helps.

Mark
Jul 20 '05 #3
"Eric Chang" <ec****@eatools.com> wrote in message news:<c8*******************@twister.socal.rr.com>. ..
I was working on this simple form with radio boxes.
And when I click on one of the radio box, it tell me the value is
"undefined"
Why is that ? I did defined the value of each radio box:

<input type=radio name='Usetax' value='basic'
onClick='document.myform.amount.value=document.myf orm.Usetax.value'>
<input type=radio name='Usetax' value='no'
onClick='document.myform.amount.value=document.myf orm.Usetax.value'>
<input type=radio name='Usetax' value='mytax'
onClick='document.myform.amount.value=document.myf orm.Usetax.value'>

Can anyone help ?

Thank a lot.

Eric
Here is the entire HTML:

<html>
<body>
<form name='myform' action='post'>
<input type=radio name='Usetax' value='basic'
onClick="document.forms[0].amount.value=document.myform.Usetax.value;
return(true);">

Default Tax

<input type=radio name='Usetax' value='no' checked
onClick="document.forms[0].amount.value=document.myform.Usetax.value;
return(true);">

No Tax

<input type=radio name='Usetax' value='mytax'
onClick="
document.forms[0].amount.value=document.myform.Usetax.value;
return(true);">
Other tax
<br>
Tax Amount: $<input type=text name=tax size=5 value=0.00><br>
total amount
<input type=text name=amount value="">
</form>

</body></html>
--

value defines the NAME of a variable that is either true (button
checked) or false (button not checked).
Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Pasquale | last post: by
reply views Thread by Adict | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.