radio box value is always undefined ?

E

Eric Chang

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.myform.Usetax.value'>
<input type=radio name='Usetax' value='no'
onClick='document.myform.amount.value=document.myform.Usetax.value'>
<input type=radio name='Usetax' value='mytax'
onClick='document.myform.amount.value=document.myform.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>


--
 
S

Stuart Palmer

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
 
G

grp_pst_363

Eric Chang said:
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.myform.Usetax.value'>
<input type=radio name='Usetax' value='no'
onClick='document.myform.amount.value=document.myform.Usetax.value'>
<input type=radio name='Usetax' value='mytax'
onClick='document.myform.amount.value=document.myform.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
 

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,777
Messages
2,569,604
Members
45,229
Latest member
GloryAngul

Latest Threads

Top