...

View Full Version : Form; why can't I return a number



cv43
10-23-2002, 06:32 PM
I'm trying to set up a form where I can select a number from a form menu, then use that number to calculate something and then display the result. Here is simple example of what I'm trying to do. Thanks in advance for for correcting my misguided ways!

<form method="POST"
enctype=application/x-www-form-urlencoded>
<p>Select a number:
<SELECT NAME="number">
<OPTION> 1
<OPTION SELECTED> 2
</SELECT>
</p>
<p>
<input name="q" value="click" type="BUTTON" Onclick = "form.answer.value=form.number.value">
</p>
<p>Number is:</p>
<input name="answer" type="INT" value="0">
<INPUT TYPE="reset" VALUE="Reset">
</form>

mhere
10-23-2002, 07:10 PM
try this:



<form method="POST" enctype=application/x-www-form-urlencoded>
<p>Select a number:
<SELECT NAME="number">
<OPTION> 1
<OPTION SELECTED> 2
</SELECT>
</p>
<p>
<input name="q" value="click" type="BUTTON" onclick = "form.answer.value=form.number.options(form.number.selectedIndex).text">
</p>
<p>Number is:</p>
<input name="answer" type="INT" value="0">
<INPUT TYPE="reset" VALUE="Reset">
</form>

cv43
10-23-2002, 07:19 PM
That worked great. Many Thanks!!!

brothercake
10-24-2002, 12:50 AM
Remember that what you get back from a form is a string, not a number - eg, "1" rather than 1. If you want to do further calculations with the numeric value, you'll need to convert it, which you can do with parseInt(n) or parseFloat(n)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum