-2

So what I want is to have a html text field where someone can type in a bit of JavaScript code, and then some kind of function that will dynamically add it into the script tag of my webpage. Any ideas?

NOTE: I don't want anything saved permanently to the server, but I do want the user-generated js to "work" and interact with my current scripts.

QuinnFreedman
  • 2,242
  • 2
  • 25
  • 42
  • asking just for asking is noth the mean of this forum. What did you tried already? what wall are you trying to pass through?... plenty examples on the web just for what you want, http://jsbin.com does that, http://jsfiddle.net does that... – balexandre Feb 11 '12 at 07:22
  • You're right. I'm sorry. I guess i gust got a little bit lazy. – QuinnFreedman Feb 11 '12 at 17:40

3 Answers3

2

eval (string) will evaluate and excute the javascript code.

Balaswamy Vaddeman
  • 8,360
  • 3
  • 30
  • 40
cotton.m
  • 455
  • 2
  • 10
1

Using jQuery:

$(document).ready(function () { 
    $('button').click(function () {
        eval($('input').val());
        });
});

Working example: http://jsfiddle.net/JL9EU/

0

Create a form, bind a handler to the submit event. Within that handler, execute the code and return false.

Kevin B
  • 94,570
  • 16
  • 163
  • 180