-1

I'm attempting to append this to my jQuery Mobile Listview. The append works correctly, however when a user clicks on the listview, triggering goToSurveyResults, it thinks that the third parameter in this function is a reference to a variable name, when in fact I simple want the string literal name. So for example, if my function is goToResults(1,2,dog), then it thinks dog is a reference to a variable. Is there a way to make javascript acknowledge that it is in fact not a variable name but a string??

$('ul#myList').append('<li><a href="javascript:void(goToResults(' + listOfSubjects[i].id + ',' + listOfSubjects[i].numberOfSubjects + ',' + listOfSubjects[i].name + '));"><h1>title<h1></li>
Apollo
  • 8,874
  • 32
  • 104
  • 192

1 Answers1

1

Try adding escaped quotes around your string value parameter like:

$('ul#myList').append('<li><a href="javascript:void(goToResults(' + listOfSubjects[i].id + ',' + listOfSubjects[i].numberOfSubjects + ',\'' + listOfSubjects[i].name + '\'));"><h1>title<h1></li>');

Example of the code working: http://jsfiddle.net/nqnpv/1/

NikB
  • 28
  • 5
  • thank you so much. The issue was actually in the definition of my function. Changing my function to window.FunctionName is actually what did it...the escaped quotes actually did nothing! – Apollo Aug 01 '12 at 18:09
  • just want to let you know that I just created another stackoverflow account so I could upvote you twice :D – Apollo Aug 01 '12 at 18:09