2
I wanted to know how to call a function through a text box. example:
<input type="text" value="load()"/>
But it’s not exactly the load function, I wish the typist could call any function even.
2
I wanted to know how to call a function through a text box. example:
<input type="text" value="load()"/>
But it’s not exactly the load function, I wish the typist could call any function even.
3
You can use the val(). Try it like this:
var input = document.querySelector('input[type=text]');
input.addEventListener('blur', function(){
eval(this.value);
});
But I strongly recommend read this about Eval();
+1 Your idea is much better than mine... nor came to mind =)
Wow, it worked/(would never think of using the Eval function). But is it guaranteed to work even with any function even? Like $('#content'). html('dddddddd')
@Iagobruno, yes. Test this: http://jsfiddle.net/326EU/2/
If I don’t engage, "seTimeout" can also do the same thing as Eval =p
If it’s not too much to ask, there would be some way to detect if the text written inside an input is something javascript?
@Iagobruno, this seems difficult :/ I think it would give a good new question! One idea (with many exceptions) is test if you have parentheses like this (link): input.value.match(/\(?(.*)\)/);
In my tests worked your method, but do you think it can give error in some case? Because I saw that it checks if it has parentheses in value..
@Iagobruno, a case where it fails is for example: "I am Sergio (John’s brother)"
2
All objects defined via direct code at the root of the scope will stop at the object window
, and so you can do so:
window["nome do método"]();
So will call the function you want by name.
0
Just use type attributes onevent
tag input
.
For example:
<input type="text" onkeydown="alert('keydown')" />
Browser other questions tagged javascript
You are not signed in. Login or sign up in order to post.
Your question is unclear. Do you want the user to type code in the input to be run? or a function that runs when the user writes text to the input?
– Sergio
input code to be run :)
– Iago Bruno
Do you generate the code through some language? if yes post here, because perhaps it is more practical to insert the
value
through her...– Kenny Rafael