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 3 of 3
  1. #1
    New Coder
    Join Date
    Oct 2005
    Location
    Camino, California.
    Posts
    70
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Trying to assign a variable the value of a hidden form, and then add a number to it.

    I understand that forms convert to strings, so I need to re-convert back to a number, and then add the amount I want. Then I re-assign the variable to the hidden form, and call it from a frame within the page.

    I'm using:


    Number(' ');

    Now I'm either using it incorrectly, or there's an error somewhere else in the code. It instead adds the two strings together still. Here's what my code looks like:

    if (classf == "bonus") {

    var maxhp = document.forms[0].elements[4].value
    var maxhp = (number(maxhp));


    maxhp = maxhp + 15;

    document.forms[0].elements[4].value = maxhp;


    }
    Currently designing and coding an entire RPG in VB

  • #2
    New Coder
    Join Date
    Oct 2005
    Location
    Camino, California.
    Posts
    70
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Whoops, got it.

    The third line of the code I listed needed to look like this:

    var maxhp = Number(maxhp);
    Currently designing and coding an entire RPG in VB

  • #3
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,518
    Thanks
    3
    Thanked 506 Times in 493 Posts
    try
    Number(maxhp)
    in place of

    number(maxhp)
    posts crossed
    but
    Number(document.forms[0].elements[4].value)

    if fine(no need for maxhp)


  •  

    Posting Permissions

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