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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variable not correct 2

Status
Not open for further replies.

jshurst

Programmer
Oct 27, 2004
1,158
US
I have a weird thing going on (at least weird in my eyes). Here is my function


Code:
function ShowDetails(pNum)
        {
        var Command = "1:" + pNum;
        var context = new Object();
        context.CommandName = "GetDetails";
        alert(pNumber);
        }

Which is wired up to a dynamically created button (inside of an asp.net datagrid). Here is the result from looking at the source.

Code:
<input type="button" id="btnName" onclick='ShowDetails(00753272)' style="background:none; cursor:hand; color:Aqua; border-style:none; font-weight:bold;" value='SMITH , JOHNNY DALE' />

So you would think that "00753272" would be the result in the alert box (or maybe just 753272).

However this gives me...251578.

This isn't in the source anywhere so I don't see where it is coming from. A few more things on the page are like that too, but the majority of buttons work correctly.

Can anyone help me out here?

Thanks in advance,

J
 
Sorry, my mistake, but that isn't the problem.

Try this

Code:
<html>
<head>
<script>
function ShowMe(v)
{
alert(v);
}
</script>
</head>
<body>
<input type="button" onClick="ShowMe(00523665)" value="Click Me" />
</body>
</html>

It appears that you can't display this number. Why is that?
 
Well, you must put single quotes inside the parentheses, I guess. But why does that number mess up?
 
The number "messes up" because by default any number that you preface with a zero is considered an octal number in Javascript, as in most C-derived languages. If any of the digits were greater than 7, you'd get an error. If you want to use leading zeros, you need to put quotation marks around the number.

Lee
 
Ah, cool, thanks for the info. I'm new to Javascript and AJAX, but so far I love it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top