Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Bizarre (very simple) behavior

Status
Not open for further replies.

strenge

Programmer
Joined
Oct 15, 2002
Messages
5
Location
US
Greetings,

I'm encountering something that is simply bizarre. I've got a Month dropdown whose option values are numbers like so:
<option value=&quot;07&quot;>July
<option value=&quot;08&quot;>August
<option value=&quot;09&quot;>September
<option value=&quot;10&quot;>October
etc.

I'm using some custom validation functions I found on the Netscape site, and found that August kept returning false in the isMonth() function. I isolated the problem statement in the function and found that the value for August bombs on a particular parseInt statement.

No other month does this.

When I do an alert on the value before the parseInt, it says &quot;03&quot; or &quot;08&quot; or whatever the value for the selected month is. After the parseInt, the other months say &quot;3&quot; or &quot;7&quot;, but good ol August reports &quot;0&quot;.
Example:
alert(themonth); //august says &quot;08&quot;
alert(parseInt(themonth)); //only august says &quot;0&quot;, other months strip the 0


Hey, it's got to be something I'm doing or not doing but I sure can't see it. I made sure the length was 2 just in case an extra unseen space was creeping in there -- all months were length 2. If all the months acted the same I'd know it was a conversion error or something, but they look identical in the source code.

Any ideas? Thanks, Rick
 
That's because if the number starts with zero, parseInt thinks it's an octal. Try adding 10 as the second argument:
alert(parseInt(themonth,10));

Adam
while(woman.width>woman.height && wallet.value>0){beer++;vision.blur()};
 
Holy Smokes, that did it.

Your fix jogged my memory to the fact that I've fallen victim to this before, years ago. We ended up always using the &quot;,10&quot;, that I remember, for the same reason.

Pretty sad to get hung up on the same thing twice, and not even remembering you had the problem before...

Thanks a bunch. That was driving me insane.

Rick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top