I have an text element I need to evaluate on change. All I need to do is open a confirm dialog asking if they'd like to save the change, if yes, I save the change and move on, if no the textbox needs to revert to it's original value. All of this works wonderfully as long as the browser window keeps focus durring the onchange event.
However if the window looses focus triggering the onchange event all hell breaks loose.
This may be related to the fact that the same element also has an onblur event... heck here's the relavant code...
Expand|Select|Wrap|Line Numbers
- <input id="mainContact" class="editableInfo" style="width: 111px;" type="text" value="customerNameHere" onfocus="editBaseballStat(this, event);" onkeydown="processBaseballStatKey(this, event);" onblur="leaveBaseballStat(this, event);" onchange="changedBaseballStat(this, event);" />
- function changedBaseballStat(element, event) {
- var textbox = $(element.id);
- if(textbox.value != this.editFieldOriginalValue) {
- if(confirm("You have changed the value of a field \n do you want to save?")) {
- this.saveBaseballStat(element);
- } else {
- textbox.value = this.editFieldOriginalValue;
- }
- }
- }
- function leaveBaseballStat(element, event) {
- var textbox = $(element.id);
- textbox.selectionBegin = textbox.selectionEnd;
- if(textbox.className == "editingInfo") {
- textbox.className = "editableInfo";
- }
- }