Saikumar Anireddy
Saikumar Anireddy

Reputation: 335

javascript error. uncaught ReferenceError

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

Answers (1)

Ranjith Ramachandra
Ranjith Ramachandra

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

Related Questions