/    Sign up×
Community /Pin to ProfileBookmark

javascript converts php string to octal

Here is the code:
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN”
http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd“>
<html lang=”EN” dir=”ltr” xmlns=”http://www.w3.org/1999/xhtml“>

<head>
<meta http-equiv=”content-type” content=”text/html;charset= utf8_unicode_ci”>
<title>Why???</title>
<script type=”text/javascript”>
function pass_var(a)
alert (a);
</script>
</head>
<body>
<?php
$a=”0150233″;
print <<<HERE
$a
<input type=”submit” onclick=”javascript: pass_var($a)”>
HERE;
?>
</body>
</html>

$a is “0150233”. But javascript converts it to 53403.

How can I keep value 0150233 in js (and retain string type).

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@Declan1991Nov 16.2011 — Any number beginning with 0 is octal. You need to wrap it in quotation marks. I haven't used PHP in a while, so I think this works, but it may not.[code=php]
print <<<HERE
<input type="submit" onclick="pass_var('$a')">
HERE;[/code]

The "javascript: " in the onclick is wrong. It shouldn't be there.
Copy linkTweet thisAlerts:
@KorNov 17.2011 — Please, don't cross-post! I have answered you here:

http://www.webdeveloper.com/forum/showthread.php?t=253518
×

Success!

Help @pananag spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...