View Full Version : help converting a string to an integer

02-27-2003, 07:45 PM
i have a dropdown of selects wher ethe options are

now i have a function that grabs the info from that and converts it into number of minutes..
for all the numbers it works fine parseInt the value.. after spliting it by : into hours and minutes

but with any number that is 08 or 09 it parseInts to 0 instead of 8 or 9

any thoughts here's my function

function checktimes() {
v_early = String(document.addform.minTime[document.addform.minTime.selectedIndex].value);
early_array = v_early.split(":");
early_mins = parseInt(early_array[0]) * 60;
early_mins += parseInt(early_array[1]);

just converts the hours/minutes to total minutes

any help is appreciated thanks

02-27-2003, 07:49 PM
You have to tell parseInt() to use a base of 10. parseInt() by default attempts to determine the base of the output. Any string with a leading zero is interpreted as octal, or a base radix of 8.

Easy fix.

early_mins = parseInt(early_array[0], 10) * 60;
early_mins += parseInt(early_array[1], 10);

02-27-2003, 07:51 PM
It's working fine... What's the problem?

(On this computer I'm using Win98 + IE 5.50.48)

Mzzl, Chris

02-27-2003, 07:52 PM
thanks, it worked after i made the change beetle recommended