473,508 Members | 2,342 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

onChange confirm and window focus.

2 New Member
I've come across a problem I just can't solve.

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
  1. <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);" />
  2.  
  3.     function changedBaseballStat(element, event) {
  4.         var textbox = $(element.id);
  5.         if(textbox.value != this.editFieldOriginalValue) {
  6.             if(confirm("You have changed the value of a field \n do you want to save?")) {
  7.                 this.saveBaseballStat(element);
  8.             } else {
  9.                 textbox.value = this.editFieldOriginalValue;
  10.             }
  11.         }
  12.     }
  13.  
  14.     function leaveBaseballStat(element, event) {
  15.         var textbox = $(element.id);
  16.  
  17.         textbox.selectionBegin = textbox.selectionEnd;
  18.  
  19.         if(textbox.className == "editingInfo") {
  20.             textbox.className = "editableInfo";
  21.         }
  22.     }
  23.  
Any idea how to get around this?
Dec 1 '06 #1
2 3914
Vyath
3 New Member
I've come across a problem I just can't solve.

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
  1. <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);" />
  2.  
  3.     function changedBaseballStat(element, event) {
  4.         var textbox = $(element.id);
  5.         if(textbox.value != this.editFieldOriginalValue) {
  6.             if(confirm("You have changed the value of a field \n do you want to save?")) {
  7.                 this.saveBaseballStat(element);
  8.             } else {
  9.                 textbox.value = this.editFieldOriginalValue;
  10.             }
  11.         }
  12.     }
  13.  
  14.     function leaveBaseballStat(element, event) {
  15.         var textbox = $(element.id);
  16.  
  17.         textbox.selectionBegin = textbox.selectionEnd;
  18.  
  19.         if(textbox.className == "editingInfo") {
  20.             textbox.className = "editableInfo";
  21.         }
  22.     }
  23.  
Any idea how to get around this?
Why would you need both onkeydown and onchange?
Dec 2 '06 #2
pendragn
2 New Member
Why would you need both onkeydown and onchange?
In this case it's because we're running a couple of special exceptions to the onchange. For example if the user hits enter it saves without prompting, and if the user hits escape it cancels the edit.

Ah the fun of duplicating full GUI Type functionality with a a web browser.
Dec 4 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
12115
by: Asit | last post by:
In JavaScripts checks for an onChange event against the value of the textbox at the time of the last onChange event. Since an onChange Event never fired after you changed the text first time ,...
1
11270
by: Christoph | last post by:
I'm trying to validate some HTML form elements when the user tabs out of each element. However, I'm having some problems. It appears that the order of events is onChange followed some time...
1
3047
by: SimonFx | last post by:
Am I right in assuming that you can NOT set focus() back to a field in its onChange event? Is there another way - I have validation that I would like to set the focus back to the invalid field...
2
3107
by: DonD | last post by:
I have a form that allows a user to upload a file. When they select a file (onChange), I call a JS function that analyzes the filename for specific keywords and then populates a multiple select box...
1
2740
by: MDBloemker | last post by:
can anyone help me fathom out how to use this bit of code: Public Class Utilities Public Shared Sub CreateConfirmBox(ByRef txt As WebControls.TextBox, _ ByVal strMessage As String)...
3
3962
by: jab3 | last post by:
Hello. I"m new to this group, and to JavaScript in general, so please forgive me if I breach local etiquette. I'm trying to implement some client-side 'dynamic' validation on a form. I'm having...
7
20844
by: Tim Slattery | last post by:
I'm trying to handle the onChange event in an <input type="file"> element. In IE, there's no problem: the event fires when a file in the "open" box is doubleclicked, or the "Open" button in the box...
1
1780
by: SimoRed | last post by:
Hi, I have a combobox with a list of links and I want to redirect (after confirming it) to a link with onChange. I use: onChange="if (confirm('do you want to redirect?')) {...
5
41821
by: ahilar12 | last post by:
hi all, i wanted to check whether the password entered matches with the confirm password.either through javascript or through php.i have enclosed my code somebody help on this <html> ...
0
7129
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7333
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7061
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7502
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5057
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4716
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3194
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1566
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
428
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.