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?
dois 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 2varlines from the top of your function body.If you’re curious what the
dokeyword is for, it’s fordo...whileloops where the condition is evaluated at the end, not the beginning of the loop. It’s used something like this:For more info check out W3Schools.