Jump to content

Ajax On Enter Rather Than On Click


lhemingway

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/286311-ajax-on-enter-rather-than-on-click/
Share on other sites

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.