How to call a function in javascript through a text box?

2

I wanted to know how I can call a function through a text box. example:

<input type="text" value="load()"/>

But it's not exactly the load function, I wanted the digitizer to call any function itself.

    
asked by anonymous 07.02.2014 / 21:10

3 answers

3

You can use eval () . Try this:

var input = document.querySelector('input[type=text]');
input.addEventListener('blur', function(){
    eval(this.value);
});

But I highly recommend read this about eval ();

Example

    
07.02.2014 / 21:14
2

All objects defined via direct code at the root of the scope will stop at the object window , so you can do this:

window["nome do método"]();

This will call the function you want by name.

    
07.02.2014 / 21:14
0

Just use the attributes of type onevent of tag input .

For example:

<input type="text" onkeydown="alert('keydown')" />

link

    
07.02.2014 / 21:34