0

I'm trying to pass a parameter to a function in JavaScript. My function code for example:

    function loadbigimage(parm){

and I'm calling with:

    <a href='javascript:;' onclick='loadbigimage(0123);'></a>"

When I'm passing random parameters that not starts with a zero (like 2400) everything is fine and parameter is passed correctly and exactly as mentioned to the function. But when I'm passing parameter which starts with a zero like '0123' the parameter passed but without the first '0' digit, so finally the vale which passed is '123' and the first zero is deleted. How can I save this issue and pass the full parameter as it is? Maybe need to pass it as a string? How can I do that?

1
  • 1
    If you want to pass it as a string, use onclick='loadbigimage("0123"); Commented Jun 3, 2013 at 15:06

1 Answer 1

2

Your number is potentially being treated as octal, although that behaviour may be browser specific. In any event, the leading zero will not be preserved.

You will either have to do without the leading zero, or pass your parameters as strings.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your answer. As I must use this leading zero how can I pass this parameter as string?
just enclose it in double quotes. Better yet, learn how to use "modern" event handlers and register the click handler using JS rather than using inline DOM0 "onclick" attributes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.