javascript - Using jQuery input event to conditionally update a <td> innerHTML -


i'd @ least me complicated.

i have in larger table:

 <table><tr>  <td class="editc" id="comments:942" onchange="timeline();" onclick="empty('comments:942');" title="click edit..."> second test of new comment behavior   </td></tr></table> 

here going on:
1) class="editc" = use editable edit , write db.
2) id="comments:942" = id value
3) onchange="timeline();" = timeline() function gets information db , puts second html table on screen. works.. no worries.
4) onclick="empty('comments:942')" = empty function empty field not update db. want clean input field enter new data in place of existing data.

what i'd happen this.

a) if typed empty field, good, save.php code save db. works great.
b) if nothing typed empty field, want old value put in place without updating db. in head equivalent first having cut current value pasting if nothing new had been typed.

it seems me jquery should able input event.

 function empty(thisid){     $(thisid).on('input',function(){        $(this).val()   // should current value     });    document.getelementbyid(thisid).innerhtml = ''; // empty field     ... what? how determine if change made? how replace original value if change wasn't made?  } 

but what? how determine if change made? how replace original value if change wasn't made?

td elements not have input event. possible nest <input> tag inside td.

$("td input").on("focusin", function() {     currentvalue = $(this).prop("value");     $(this).prop("value", ""); }).on("focusout", function() {     if($(this).prop("value") === "") {         $(this).prop("value", currentvalue);     } }); 

here, when input clicked, found using focusin event, value of input stored in global variable. needs global, because have use variable in next function. after variable stored, input field erased, setting value attribute empty string.

if user didn't make changes , leaves input field, detected focusout event, value attribute reset once was.

current fiddle

http://jsfiddle.net/a592awoo/1/


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -