code_junkie

How do I escape a string inside javascript inside an onClick handler?

Nov 11th, 2011
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. <a href="#" onclick="SelectSurveyItem('<%itemid%>', '<%itemname%>'); return false;">Select</a>
  2.  
  3. <a href="#" onclick="SelectSurveyItem('<% JSEncode(itemid) %>', '<% JSEncode(itemname) %>'); return false;">Select</a>
  4.  
  5. <a id="tehbutton" href="somewhereToGoWithoutWorkingJavascript.com">Select</a>
  6.  
  7. <script type="text/javascript">//<!-- <![CDATA[
  8. jQuery(function($){
  9. $("#tehbutton").click(function(){
  10. SelectSurveyItem('<%itemid%>', '<%itemname%>');
  11. return false;
  12. });
  13. });
  14. //]]>--></script>
  15.  
  16. <a id="link_1" href="foo">Bar</a>
  17. <a id="link_2" href="foo2">Baz</a>
  18.  
  19. <script type="text/javascript">
  20. jQuery(function($){
  21. var l = [[1,'Bar'],[2,'Baz']];
  22. $(l).each(function(k,v){
  23. $("#link_" + v[0] ).click(function(){
  24. SelectSurveyItem(v[0],v[1]);
  25. return false;
  26. });
  27. });
  28. });
  29. </script>
  30.  
  31. <a id="someLinkId"href="#">Select</a>
  32. <script type="text/javascript">
  33. document.getElementById("someLinkId").onClick =
  34. function() {
  35. SelectSurveyItem('<%itemid%>', '<%itemname%>'); return false;
  36. };
  37.  
  38. </script>
  39.  
  40. <a href="#" itemid="<%itemid%>" itemname="<%itemname%>" onclick="SelectSurveyItem(this.itemid, this.itemname); return false;">Select</a>
Add Comment
Please, Sign In to add comment