Show them the default, and allow them to press escape or Ctrl-Z

Posted by cf_PhillipSenn on Stack Overflow See other posts from Stack Overflow or by cf_PhillipSenn
Published on 2010-03-30T03:07:14Z Indexed on 2010/03/30 3:13 UTC
Read the original article Hit count: 306

Filed under:

I have a table cell, and when the user clicks on it, I replace the contents of the table cell with an input tag with the current contents as the default. But I don't like it's behavior because there's a chance that the user can delete the contexts on the input simply by clicking on it a second time.

 $('.LastName').live('click', function() {
  var myText = $(this).text();
  $(this).empty().append('<input name="LastName" id="LastName" value="' + myText + '" />');
  document.myForm.LastName.focus();
 });

Q: How do I give the user a default, plus allow them to press the escape key or Ctrl-Z while in the middle of an edit?

© Stack Overflow or respective owner

Related posts about jQuery