Good day.

I am familiar with JS very remotely, for this reason some banal things seem to me completely scary and impracticable. But I need to solve one problem.

Decided to make a dynamic table with a garter from a DB. Found a great thing PHP MySQL Inline Editing using jQuery Ajax I downloaded, installed, everything works.

To edit the cell, I need to click anywhere, but I want to use the traditional way, just press Enter and that's it. Here it does not go down, when clicking on Enter we move to a new line, even if I remove this line break in the database, it still writes <br> .

The function is responsible for updating the database:

 <script> function saveToDatabase(editableObj,column,id) { $(editableObj).css("background","#FFF url(loaderIcon.gif) no-repeat right"); $.ajax({ url: "saveedit.php", type: "POST", data:'column='+column+'&editval='+editableObj.innerHTML+'&id='+id, success: function(data){ $(editableObj).css("background","#FDFDFD"); } }); } </script> 

Actually the question is what and where you need to change in this code, so that you can just press Enter and everything is recorded. I do not need line breaks.

Thank you in advance!

  • $ (document) .keypress (function (e) {if (e.which == 13) {alert ('You pressed enter!');}}); If you need to press the ENTER key - Daniel

1 answer 1

Probably something like that you need:

 $(document).keypress(function(e) { e.preventDefault(); if(e.which == 13) { function saveToDatabase(editableObj,column,id) { $(editableObj).css("background","#FFF url(loaderIcon.gif) no-repeat right"); $.ajax({ url: "saveedit.php", type: "POST", data:'column='+column+'&editval='+editableObj.innerHTML+'&id='+id, success: function(data){ $(editableObj).css("background","#FDFDFD"); } }); } } }); 
  • Alas, it did not help, a line break appears. + the whole data is now not recorded in the database - OuFinx
  • @OuFinx try this, update the answer, it can help. - Daniel