Reputation: 335
I am trying to write an anchor tag in a for
loop, and sending parameters to a function in onclick
event.
Now the problem is that the function does not pass the parameter which is in a variable instead it is getting an error "Uncaught ReferenceError: I is not defined ", where I is the value in the variable catidone.
catlisttxt += '<li>'+catidone+'<a href="#" onclick="return DisplayQues('+ catidone +')">'+data.categories[i].maincatname+'</a></li>';
Upvotes: 2
Views: 1558
Reputation: 10764
catlisttxt += '<li>'+catidone+'<a href="#" onclick="return DisplayQues(\''+ catidone +'\')">'+data.categories[i].maincatname+'</a></li>';
Try escaping the quotes. I think when you do this, it actually sees this as DisplayQues(I) instead of DisplayQues('I')
Upvotes: 4