lhemingway Posted February 19, 2014 Share Posted February 19, 2014 if(editTblRow==null && editTblCell==null){ if(fieldtype!='blob'){ $($('#ajaxtb')[0].rows[rowid].cells[cellid]).html('<input type="text" id="edit_box" class=\"edit_input\" value=\"' + id + '\" /><div class=\"cell_opts\"><a href=\"javascript:return false;\" onclick=\"' + "editCell('','','','','','save','','" + updatestring + "');" + '\">Save</a> - <a href=\"javascript:return false;\" onclick=\"' + "editCell('','','','','','cancel');" + '\">Cancel</a></div>'); } else { $($('#ajaxtb')[0].rows[rowid].cells[cellid]).html('<textarea id="edit_box" class=\"edit_input\" value=\"' + id + '\" >' + id + '</textarea> <div class=\"cell_opts\"><a href=\"javascript:return false;\" onclick=\"' + "editCell('','','','','','save','','" + updatestring + "');" + '\">Save</a> - <a href=\"javascript:return false;\" onclick=\"' + "editCell('','','','','','cancel');" + '\">Cancel</a></div>'); } The following code submits data in the input field of an ajax table on the click of the save button but I would like to change it to update on the enter key how can I change the code to do this? Any help would be appreciated. Regards Luke Quote Link to comment https://forums.phpfreaks.com/topic/286311-ajax-on-enter-rather-than-on-click/ Share on other sites More sharing options...
denno020 Posted February 22, 2014 Share Posted February 22, 2014 (edited) When you hit enter whilst entering text in an input field in a form, that form will submit.. The input field needs to be surround by a <form> for this to work. If you don't have <form> tags around your input, then you can use this code that I found from a Google search at stackoverflow: $(document).keypress(function(e) { if(e.which == 13) { alert('You pressed enter!'); } }); And put into practice here: http://jsfiddle.net/Gehtf/1/ Hope that helps Denno Edited February 22, 2014 by denno020 Quote Link to comment https://forums.phpfreaks.com/topic/286311-ajax-on-enter-rather-than-on-click/#findComment-1470018 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.