[Javascript] Bizarre IE behaviour.

Matt Barton javascript at mattbarton.org
Fri Aug 13 03:08:10 CDT 2004


Excellent.  Thanks very much Hakan - that had me tearing my hair out.  As it
happens I got round it by doing:

// -------
    intDay = strDay / 1;
// -------

... but at least my mind is now at rest.

Matt

----- Original Message ----- 
From: "Hakan Magnusson (Backbase)" <hakan at backbase.com>
To: "[JavaScript List]" <javascript at LaTech.edu>
Sent: Thursday, August 12, 2004 6:30 PM
Subject: Re: [Javascript] Bizarre IE behaviour.


> You're not going mad, but unless you specify the radix argument parseInt
> tries to determine what kind of base you provide it with, and for
> strings that start with '0' it assumes an octal value. The solution is
> to specify the radix that parseInt should use (10 in your case, 16 for
> hexadecimal etc). Here's the code:
>
> <html>
>   <body>
>    <script>
>     var strDay = '09';
>     var strMonth = '06';
>     var strYear = '2004';
>     alert (strDay);
>     alert (strMonth);
>     alert (strYear);
>
>     var intDay = parseInt (strDay, 10);
>     var intMonth = parseInt (strMonth, 10);
>     var intYear = parseInt (strYear, 10);
>     alert (intDay);
>     alert (intMonth);
>     alert (intYear);
>
>    </script>
>   </body>
> </html>
>
>
> The behaviour is the same for Mozilla, so I think it's safe to assume
> that this is how the function is supposed to work according to
> ECMAScript standards.
>
> Regards,
> H
>
>
>
> Matt Barton wrote:
> > This is probably me being fantastically short sighted, but I've noticed
> > behaviour in IE this afternoon which was wholey unexpected, and also
plain
> > wrong ("so tell us something new", say the open source fraternity).
> >
> > This is the situation.  I have a very simple page:
> >
> > ----------------------------
> > <html>
> >  <body>
> >   <script>
> >    var strDay = '09';
> >    var strMonth = '06';
> >    var strYear = '2004';
> >    alert (strDay);
> >    alert (strMonth);
> >    alert (strYear);
> >
> >    var intDay = parseInt (strDay);
> >    var intMonth = parseInt (strMonth);
> >    var intYear = parseInt (strYear);
> >    alert (intDay);
> >    alert (intMonth);
> >    alert (intYear);
> >
> >   </script>
> >  </body>
> > </html>
> > --------------------
> >
> > When it loads I would expect to see six consecutive alert boxes
containing,
> > in order, the following strings: "09", "06", "2004", "9", "6", "2004".
> >
> > However, in IE6/Win (on two separate machines in my office) the fourth
alert
> > box contains "0".
> >
> > Does anyone else see this behaviour?  Tell me I'm not going mad ...
> >
> > Oh - I've tested it on Opera (the only other browser I have immediate
access
> > to without installing another) and it works exactly as I would expect it
to.
> >
> > Matt
> >
> > _______________________________________________
> > Javascript mailing list
> > Javascript at LaTech.edu
> > https://lists.LaTech.edu/mailman/listinfo/javascript
> >
> >
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript
>
> -- 
> This email has been verified as Virus free
> Virus Protection and more available at http://www.plus.net




More information about the Javascript mailing list