First, modify AddInput to set a listener for the blur event, which will fire when something other than this element gets clicked:
function AddInput(td){ var ip=zxcAddField('INPUT','text',''); ip.value=td.innerHTML; ip.onblur = function () { removeInput(ip); }; td.innerHTML=''; td.appendChild(ip); td.onmouseup=null; }
Then you can add a new removeInput function that will replace the contents of the <td> when the <input> triggers a blur event:
function removeInput(input) { var val = input.value; var td = input.parentNode; td.removeChild(td.lastChild); td.innerHTML = val; td.onmouseup = function () { AddInput(td); }; }
This function also reassigns the mouseup event listener, since it gets null in the AddInput function.
Keep in mind that while this worked for me in Chrome 22, it will probably take a little extra effort to test and fix any cross-browser issues with built-in events and attribute assignments.
If this were my code, I would probably rewrite the "standard" version with addEventListener and getAttribute() / setAttribute() , and then create only the correcting IE path using its equivalents. Or just use jQuery and let it do all the cross-browser stuff for you.
source share