1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Javascript {.value} question

Discussion in 'JavaScript' started by askscript, Sep 5, 2016.

  1. #1
    Hi, i need to help to learn this. Thanks in advance.

    <label>Value 1</label> <input type="text" id="value1" name="value1" /><br />

    <script>

    var num1 = document.getElementById("value1");
    parseInt(num1.value) // this gives an integer when you key in an integer in the input box.

    var num1 = document.getElementById("value1").value;
    parseInt(num1) // this gives NaN when you key in an integer in the input box.
    </script>

    May i know why the difference?
     
    askscript, Sep 5, 2016 IP
  2. Blizzardofozz

    Blizzardofozz Well-Known Member

    Messages:
    132
    Likes Received:
    9
    Best Answers:
    1
    Trophy Points:
    118
    #2
    Should work both ways. How are you getting the value of the input filed? The reason for NaN is that you are getting the value when the field is empty.
     
    Blizzardofozz, Sep 5, 2016 IP