I’m working on a code generator and I am wondering if I can inject javascript into a text box USING javscript.
I do not want the injected javascript to be executed, and I’m worried that the quotes in the string may cause errors.
For example, I want to inject this script:
$('#click').function(){
$('#thing').html('<a href="user.php">User</a>');
}
into this textbox:
<textarea rows="3" cols="20" id="textbox">
</textarea>
Using javascript(jQuery)’s .html().
How can I achieve that?
Just set the value of the element:
You’ll have to make sure that the quote characters in the code you want to put into the
<textarea>are quoted, but that’s because you’re expressing JavaScript source code in JavaScript and doesn’t really have anything to do with the HTML element.