String parameters in a javascript function -
im having function:
<script> function params(a,b,c,d) { // alert (c); var question = document.getelementbyid("question"); question.value = c; var answer = document.getelementbyid("answer"); answer.value = d; var catid = document.getelementbyid("catid"); catid.value = a; var qid = document.getelementbyid("qid"); qid.value = b; } <button class="modalinput" rel="#prompt" onclick="params(29,29,'in fox tv show, did 'the oc' stand for','orange county');"><img src=/images/exclamationmark1.png title="is there error in question, report here." ></button> <button class="modalinput" rel="#prompt" onclick="params(29,16,'which reality show named after george orwell character','big brother');"><img src=/images/exclamationmark1.png title="is there error in question, report here." ></button>
first button doesnt work, because of #&039; - second 1 does... first 1 did come using htmlspecialchars() on string... thought trick?
you can see page on here:
it's not html needs escaped there. html character escape sequence '
yield single apostrophe, javascript code
params(29,29,'in fox tv show, did 'the oc' stand for','orange county');
obviously syntax error. need escape string delimiters backslash:
<button … onclick="params(29,29,'in … did \'the oc\' stand for',…);">
or need use quotes string delimiters - indeed need html-escaped, since used html attribute delimiters:
<button … onclick="params(29,29,"in … did 'the oc' stand for",…);">
of course, @kirill ivlev right. shouldn't have used inline event handler attributes in first place, unobtrusive javascript. if attach listeners scripts code, won't have encoding problems.
Comments
Post a Comment