javascript that produces functioning javascript
NickName:David Ask DateTime:2011-05-23T10:07:09

javascript that produces functioning javascript

can you write javascript that produces/writes/etc. functioning javascript?

for example, have a link that has a function tied to it that when clicked produces a functioning javascipt snippet? The snippet could deal with a completely other elements.

For example

Link #1(has the javascript function that produces javascript) Link #2(does absolutely nothing for now)

Click on link #1(produces javascript snipped that says "when link #2 is clicked document.write('hello')"

Clicking on link #2 now produces "hello" whereas it previously did nothing. Is that possible?

Copyright Notice:Content Author:「David」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/6092157/javascript-that-produces-functioning-javascript

Answers
Gordon Gustafson 2011-05-23T02:18:18

Yes, you can dynamically assign event handlers described in text.\n\nHowever, dynamic code generation is far more difficult than it sounds unless you're just following basic patters and replacing certain variables. Writing programs that write programs has long been a fascination of the computer industry, and this gave way to functional programming, which can be done in javascript.",


Drew 2011-05-23T02:47:19

Create the input/delete keys on the onClick handler for the datepicker, you can attach date information (or other data) when the input(s) are created. Now, you should look into $.delegate() for how to bind handlers to those inputs created. $.delegate can bind handlers to elements that are not created yet, so when they are created they will fire a handler. By storing date relevant information in the inputs via $.data() or data- attributes you will have context aware handlers for dealing with things.",


More about “javascript that produces functioning javascript” related questions

javascript that produces functioning javascript

can you write javascript that produces/writes/etc. functioning javascript? for example, have a link that has a function tied to it that when clicked produces a functioning javascipt snippet? The s...

Show Detail

Twitter javascript not functioning?

I am using the following code on my website for the twitter widget and it recently stopped functioning. Could anyone tell me why? My website is http://www.lookbookcookbook.com/ Thanks! <div st...

Show Detail

Exclude JavaScript from functioning at certain screen size

I would like to exclude this JavaScript from functioning at a screen size smaller than 768px. Do you know what I need to add to the code? <script type="text/javascript"> var timeOut;

Show Detail

JavaScript element formatting in Partial view, but not functioning

A javascript element works in the main view, but doesn't do anything in the partial view. It is formatted correctly, but its not functioning. Any suggestions? See this fiddle: http://jsfiddle.net/...

Show Detail

Exit Pop Javascript not functioning properly

I have been trying to get this exit pop to work. So far I can get it to work on a Mac in FF, Chrome and Safari, but struggling with IE, FF, Chrome for Windows. These are two snippets that I have tr...

Show Detail

Including jQuery causes standard JavaScript to stop functioning?

I'm getting started with jQuery. I'v been trying to mix it with some of my preexisting JavaScript code so I don't have to rewrite everything. I have read many places that this is totally doable.

Show Detail

Javascript clock not functioning

Created a javascript clock but it's not functioning The css styled it correctly, but it's not actually telling the time. Tips and suggestions would be very much appreciated, thanks! If you can, ple...

Show Detail

Matching Regular Expression for URLS in JavaScript Produces null

I have the following regular expression which I have validated: "(http|ftp|https)://([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:/~+#-]*[\w@?^=%&/~+#-])?" I have the following Javascript code

Show Detail

Print PHP JSON encoded array, to JavaScript and decode it, produces errors

I have to use some data from PHP to JavaScript. I am using JSON for that. I encode the array with PHP's json_encode function and then I want to decode it with JavaScript. <?php $data = array( "...

Show Detail

Javascript is not functioning properly, please have a quick look to debug

I have a bit of Javascript which exists in a PHP script. Here it is: // start of JS script print("<script type=\"text/javascript\"> <!--\n"); print("function storeData()"); print(&qu

Show Detail