Function Passing Arg With Quotes

[Total: 0    Average: 0/5]

This shows how to deal with strings that have quotes (single or double) when you need to pass that string to an HREF-Javascript routine as an arugment.

Body Code:

<script type=text/javascript>
function doIt1(_x) { alert(_x.value); }
function doIt2(_x) { alert(_x); }
var _var1 = 'some text' or more "text';
document.write('<a href="javascript:document.exf1.hideme.value=_var1;doIt1(document.exf1.hideme)">');
document.write(_var1);
document.write("</a><BR><BR>");
document.write('<a href="javascript:document.exf1.hideme.value=_var1;doIt2(document.exf1.hideme.value)">');
document.write(_var1);
document.write("</a>");
</script>
<form name=exf1>
<input type=hidden name=hideme>
</form>

Times Viewed: 0

Leave a Reply

Your email address will not be published. Required fields are marked *