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 5 of 5
  1. #1
    Regular Coder
    Join Date
    Nov 2005
    Posts
    148
    Thanks
    1
    Thanked 0 Times in 0 Posts

    compare problem.

    i have the problem when compare tow value by usign javascript.

    the following is my situation:
    i had two variable that get the value from a form that create by using PHP language and plus 1 to the both variable and show out the result.
    i had check that i had get the value and assign to the two variable that code by javascript.

    for example:
    variable1 = document.getElementById('startGroup').value;
    variable2 = document.getElementById('endGroup').value;

    temp1 = variable1 + 1;
    temp2 = variable2 + 1;

    //the value get the form that i had pass, i check it
    //variable1 = 1;
    //variable2 = 10;

    //but the output
    temp1 = 11
    temp2 = 101

    how should i solve the problem??
    isnt any code for javascript that convert the char to the integet??

    anyone can help me??
    thanks.

  • #2
    gph
    gph is offline
    Regular Coder
    Join Date
    Apr 2005
    Posts
    161
    Thanks
    0
    Thanked 0 Times in 0 Posts
    variable1 = parseInt(document.getElementById('startGroup').value);

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    Or you could use parseFloat if you are expecting decimal numbers. Or even Number() function, it both covers integers and floating numbers.

    variable1 = Number(document.getElementById('startGroup').value);

  • #4
    Regular Coder
    Join Date
    Sep 2005
    Posts
    535
    Thanks
    0
    Thanked 0 Times in 0 Posts
    See this thread.
    If you want answers, write a smart question.

    Yes, someone probably does know how...

    Oh, and if you want to learn, STFW!

  • #5
    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
    apart some readonly values exceptions, all the attributes values are returned as strings in javascript, so that you must transform them into numbers, using, according to your needs, some methods: Number(), parseInt(), parseFloat()... a.s.o
    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
    •