Skip to content

Instantly share code, notes, and snippets.

@psycalc
Last active July 2, 2016 10:56
Show Gist options
  • Save psycalc/6d7832bdc9d185f9fd0efb9e8c9bade4 to your computer and use it in GitHub Desktop.
Save psycalc/6d7832bdc9d185f9fd0efb9e8c9bade4 to your computer and use it in GitHub Desktop.
Covert string to code that can be performed (invoked, run, call and so on)
<!-- need bootstrap.css for quick start -->
<div class="container">
<h2>Form control: textarea</h2>
<p>The form below contains a textarea for comments:</p>
<form role="form">
<div class="form-group">
<label for="comment">Comment:</label>
<textarea class="form-control" rows="5" id="comment"></textarea>
<button type="button" class="btn btn-default">Default</button>
</div>
</form>
</div>
var textarea = document.getElementsByTagName("textarea")[0];
textarea.value = "Hello World";
var button = document.getElementsByTagName("button")[0];
button.addEventListener("click", function () {
(new Function(textarea.value))();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment