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
    Mar 2004
    Location
    Milky Way Galaxy
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Handling the textbox entry as a number

    I'm having a problem with the following. I am trying to add the number entered in the text box to the variable vduron13. Everytime that i add however it returns the textbox entry then its old value. For example, entering 5 into the textbox would return 50 and if repeated 550 and so on. Does anyone know how would I fix this?

    vduron13 = 0;
    var quantity = 0;
    var quantity = document.form.duron13amount.value;
    vduron13 = quantity+vduron13;
    Last edited by CreativeGPX; 03-19-2004 at 08:08 PM.

  • #2
    Regular Coder
    Join Date
    Apr 2003
    Location
    Atlanta, GA
    Posts
    487
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Handling the textbox entry as a number

    Code:
    vduron13 = 0;
    var quantity =new  Number(document.form.duron13amount.value);
    vduron13 = quantity+vduron13; 
    Using the Number() constructor will give you a math-able (?) number based on the string input. Ha HA! More versatile than parseFloat() and parseInt().

    Unless I'm wrong again.

    Also: You can't legally initialize the same variable with the "var" keyword more than once.

  • #3
    New to the CF scene
    Join Date
    Mar 2004
    Location
    Milky Way Galaxy
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks it works perfect. And about the only using var once, I did that in my code, but i guess that i messed it up typing it on here.

  • #4
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    In fact Number() it is used for other purposes than parseInt(). Eachone has its merrits

    parseInt('123') and Number('123') will do the same, but

    only parseInt('123 px') will return 123

    only Number(true) will convert the boolean to 1
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

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