Dynamically call a javascript function.

2790 pts.
Tags:
HTML
JavaScript
JavaScript Automation
JavaScript functions
Lets see if I can explain it. I have an INPUT html element, and I has stored some value on it. This value is a javascript function name like this:
<input id="myinput" value="doSomething();" type="hidden">
In a javascript function I'm getting the variable this way:
var aFunction = document.getElementById('myinput');
If aFunction  is not null then I need to call the function stored on it, in other words, I need to call
"doSomething();"
. The problem is that the value of 'myinput' is variable and at this point I don't know it. I wonder if there is a way to do something like this in javascript. Thank you for any suggestion.

Software/Hardware used:
javascript, firefox, IE, JSF

Answer Wiki

Thanks. We'll let you know when a new response is added.

Mario, have you tried the <a href=”http://www.w3schools.com/jsref/jsref_eval.asp”>eval() Function</a> ?

Something like this:

<pre>eval(aFunction.value);</pre>

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Mariodlg
    Thanks Carlosdl, it was the solution!
    2,790 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following