2

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>';
2
  • Don't use onclick attributes. It makes life easier. Commented Oct 19, 2012 at 11:47
  • Why not. If you are a new guy learning Javascript,you might want to. Sure, Jquery.click is good, but you need to know about it in the first place Commented Oct 19, 2012 at 11:55

1 Answer 1

4
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')

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

Comments

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.