I want to call a function when Enter key is pressed in a input text area when the cursor is flashing.
How would you solve this?
Also, I want it to be functional on both FF and IE.
Thank youuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu!
enter key in text(type) input(element name)
Moderator: General Moderators
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: enter key in text(type) input(element name)
I would use jquery to greatly simplify the task and cross browser compatability issues.
I.e.,
I.e.,
Code: Select all
$(function() {
var inputBox = $('#id_of_your_input');
var keyCode = null;
inputBox.keypress(function(e) {
keyCode = (e.keyCode ? e.keyCode : e.which);
if (keyCode == 13) {
alert('Enter key pressed.');
}
e.preventDefault();
});
});Re: enter key in text(type) input(element name)
Thank you, John.
But, I could somehow get it to work testing many codes.
Though I'm aware that this is really bad programming, I use this for now.
I'm a real newbie to Javascript and PHP with self-learning, by the way.
// for FF
elementName.onkeydown=function(e){
if(e.keyCode==13){
functionName();
return false;
}
};
//for IE
elementName.onkeyup=function(){
if(window.event.keyCode==13){
functionName();
return false;
}
};
And, I'll come to see your code when the time comes that I'm really ready to learn JQuery.
But, I could somehow get it to work testing many codes.
Though I'm aware that this is really bad programming, I use this for now.
I'm a real newbie to Javascript and PHP with self-learning, by the way.
// for FF
elementName.onkeydown=function(e){
if(e.keyCode==13){
functionName();
return false;
}
};
//for IE
elementName.onkeyup=function(){
if(window.event.keyCode==13){
functionName();
return false;
}
};
And, I'll come to see your code when the time comes that I'm really ready to learn JQuery.