Reputation: 15925
Is it possible to execute a function by pressing the enter key on the keyboard only if a certain textbox has focus. i.e. if any other textbox has focus or no textbox has focus, the enter key should do nothing.
Upvotes: 13
Views: 13622
Reputation: 9954
Enter any thing in Text box then press Enter to execute
<form onSubmit='alerttest(this); return false'>
<input type="text">
</form>
<script language="javascript">
function alerttest()
{
alert("Executing jolly.exe !!!!");
// function edited by Inderpreet singh
}
</script>
Upvotes: -2
Reputation: 50966
$(function(){
$("#textarea").keyup(function(e){
if (e.keyCode === 13) {
//do stuff
}
});
});
Upvotes: 5
Reputation: 6260
$('#myTextbox').bind('keyup', function(e) {
if ( e.keyCode === 13 ) { // 13 is enter key
// Execute code here.
}
});
Upvotes: 32