// On double click show the input box
$( "#text1" ).dblclick(function() {
$( "#text1" ).hide();
$( "#text1_input" ).val($( "#text1" ).html()); // Copies the text of the span to the input box.
$( "#text1_input" ).show();
$( "#text1_input" ).focus();
});
// What to do when user changes the text of the input
function textChanged(){
$( "#text1_input" ).hide();
$( "#text1" ).html($( "#text1_input" ).val()); // Copies the text of the input box to the span.
$( "#text1" ).show();
// Here update the database
}
// On blur and on enter pressed, call the textChanged function
$( "#text1_input" ).blur(textChanged);
$( "#text1_input" ).keypress(function (e) {
var key = e.which;
if(key == 13) // the enter key code
{
textChanged();
return false;
}
});
Leave a Reply