Reputation: 923
I have a dialog box with an ok button, the ok button works, but i want the user to be able to press enter on the keyboard as well, this is the code i have, any suggestions?
function showDialog()
{
$('#dialog').dialog('destroy');
$('#dialog').show();
$('#dialog').html();
$("#dialog").dialog({
resizable: false,
modal: true,
height: 120,
width: 370,
overlay: {
backgroundColor: '#000',
opacity: 0.9
},
title:"Enter possible answer"
});
}
Upvotes: 0
Views: 1416
Reputation: 334
$(document).ready(function(){
$("#dialog").keyup(function(event){
if(event.keyCode == 13){
// your code
showDialog();
}
});
})
Upvotes: 1
Reputation: 11114
$('#dialog').onKeyDown(function (e) {
if (e.which == 13) {
// just trigger the submit handler
alert('Enter');
}
Upvotes: 0
Reputation: 10012
You will want to catch the keypress event:
if (e.keyCode == 13) {
//code
}
That JS will check whether or not the enter key was pressed, this code will work on all browsers/platforms.
Upvotes: 0
Reputation: 5356
document.onkeypress=function(e){
if(e.keyCode==13)
{
showDialog();
}
}
Upvotes: 2