Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Oct 2002
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Form; why can't I return a number

    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>

  • #2
    New Coder
    Join Date
    Aug 2002
    Location
    Pakistan
    Posts
    56
    Thanks
    0
    Thanked 0 Times in 0 Posts
    try this:

    Code:
    <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>

  • #3
    New to the CF scene
    Join Date
    Oct 2002
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That worked great. Many Thanks!!!

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •