Friday, November 16, 2012

javascript – Add a parameter to a dynamic function

I have a generic javascript class that creates an html input element. The code allows me to pass a function as a string that will be called whenever the value of the element changes, using jQuery\’s change method. I\’m using the following code:



1. var changeFunction = \"runThisCode()\";
2.
3. var elem = $(\"<input/>\").attr(id: someID, type: \"text\", size: 20);
4. elem.change(function () {
5. var fn = new Function(changeFunction);
6. fn();
7. });


I\’d like to pass the id of the element in the change function. Is there a way for me to add a parameter at either on line 5 or 6?






Rating: 3 out of 5 based on 3 ratings



The post javascript – Add a parameter to a dynamic function appeared first on Javascript ASK.






via Javascript ASK http://javascriptask.phpfogapp.com/javascript-add-a-parameter-to-a-dynamic-function.html

No comments:

Post a Comment