streetparade
streetparade

Reputation: 32878

Pass Parameter to JavaScript

I'm trying to pass two parameters to a JavaScript function. Unfortunately this give me error.

Here is the function

    function load(do,div)
    {
        var do;
        var div;
        document.getElementById('spinner').innerHTML = '<img src=\'/images/spinner.gif\'>';
        $('#'+div).load('rpc.php?'+do,
        function()
        {
            document.getElementById('spinner').innerHTML = '';
            $('#'+div).show('slow');
        }
    }

And I call it like this:

    <a href="javascript:;" onclick="load('limit','mydiv');">Get Limit</a>

How can I fix that?

Upvotes: 0

Views: 408

Answers (3)

Asaph
Asaph

Reputation: 162781

do is a reserved word in JavaScript. Change the variable name to something else. Additionally, don't re-declare the arguments in the function body. So remove the 2 var lines from the top of your function body.

If you're curious what the do keyword is for, it's for do...while loops where the condition is evaluated at the end, not the beginning of the loop. It's used something like this:

do {
    // do stuff in loop at least once
} while (some_condition_is_true);

For more info check out W3Schools.

Upvotes: 11

dhaval
dhaval

Reputation: 2388

Is it because you are redefining do div again in function and they are overriding the scope of passed parameters?

Upvotes: 1

gahooa
gahooa

Reputation: 137282

do is a reserved word in JavaScript.

http://javascript.about.com/library/blreserved.htm

Upvotes: 2

Related Questions