#1
  1. a lazy guy
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2001
    Location
    Hong Kong
    Posts
    99
    Rep Power
    14

    Javascript: String <-> Integer


    Hello,

    I got a problem with the following codes:

    <html>
    <script>
    function cal(myForm)
    {
    var age = myForm.MyAge.options[myForm.MyAge.selectedIndex].value;

    var myNum = age + 1;
    alert(myNum);
    }
    </script>
    <form name="myForm">
    <select name="MyAge" onChange="cal(this.form)">
    <option value="1">1</option>
    <option value="2">2</option>
    </select>
    </form>
    </html>


    it prints '11' or '21', but not summing up the value.
    anyone got a solution?

    thanks.,
  2. #2
  3. a lazy guy
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2001
    Location
    Hong Kong
    Posts
    99
    Rep Power
    14

    solved


    the problem above is solved by using parseInt();

IMN logo majestic logo threadwatch logo seochat tools logo