开发者

Javascript problem - not passing string with leading '0' to string properly

I have a weird problem. I have a simple function to open a popup with information about a pin (by clicking on a link with that PIN)

It works fine for some pins, but converts others to a different number.

For example passing '开发者_如何学JAVA033604' opens http://mysite.com/pincheck.php?pin=014212

but passing '023960' opens http://mysite.com/pincheck.php?pin=023960 (what I need)

Passing '032765' opens http://mysite.com/pincheck.php?pin=013813

but passing '030309' opens http://mysite.com/pincheck.php?pin=030309 (what I need)

I've tried a bunch of pins and it's all random like that - either passes the correct pin or converts it to a different number

The function is

function win_open_pin(pin) {
newwindow = window.open('pincheck.php?pin=' + '0' + pin + '' , 'popupwin', 'menubar=no,history=no,resizable=yes,scrollbars=yes,toolbar=no,width=650,height=300');
if (window.focus) {newwindow.focus()}
}

I did try using pincheck.php?pin=0' + pin and did try pin = toString(pin) in the function - no use

The call is also simple

<a href=\"javascript:win_open_pin($pin)\">$pin</a> 

The $pin variable in php is taken from the db and is a string, I even did (string) casting just in case. It seems to be js issue, as I never had issues like that with php.

I don't see any rhyme or reason to this. Hope someone can point me in the right direction to solve this. Thanks.


I think its an issue with the automatic int conversion. e.g:

parseInt("033604", 10) //returns 33604

parseInt("033604") //returns 14212 - Octal

Change the anchor element markup to following(notice the single quotes around $pin):

<a href=\"javascript:win_open_pin('$pin')\">$pin</a>


DEC 013813 = OCT 032765 Javascript assumes a number is Octal if it starts with a leading zero.Description. Adding quotes around $pin should resolve the issue for you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜