View Full Version : compare problem.

12-18-2005, 04:23 PM
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??

12-18-2005, 05:06 PM
variable1 = parseInt(document.getElementById('startGroup').value);

12-19-2005, 11:41 AM
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);

12-19-2005, 03:04 PM
See this thread (http://www.codingforums.com/showthread.php?t=74992).

12-19-2005, 04:58 PM
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