473,506 Members | 17,309 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Capture when a textbox has changed!

Hi!

Does anybody of you have a good algorithm to capture when a value in a
textbox is changed? I'm using the keypress/keydown events but they seems to
be a bit inconsistent (IE and Mozilla). Basically what I want is to set is a
"isDirty" flag when a user has changed any value in the textbox (or in a
dropdown) and then if he/she tries to leave the record without saving I want
to give a save warning. Since I don't want set the isdirty flag if you for
example klick tab, certain F-buttons, arrows (up/down/left/right) etc I
tried to capture the keypress/keydown event and ignore specific keycodes.
Since there are several keycodes that should be ignored I was hoping there
is a better solution.

Must support IE6 and NN7+ (mozilla). Since the site is unicode compatible
the user may add chinese characters for example.

Regards
/Hans
Jul 23 '05 #1
7 2947
On Wed, 29 Sep 2004 12:12:21 +0200, Hans <so***@nospam.com> wrote:
Does anybody of you have a good algorithm to capture when a value in a
textbox is changed?


Umm, the change event, perhaps?

[snip]

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #2
use the onChange() event mate, trying to grab key press's is a bit of a
nightmare as key's like "del", "backspace" behave differently!
"Hans" <so***@nospam.com> wrote in message
news:cj**********@green.tninet.se...
Hi!

Does anybody of you have a good algorithm to capture when a value in a
textbox is changed? I'm using the keypress/keydown events but they seems to be a bit inconsistent (IE and Mozilla). Basically what I want is to set is a "isDirty" flag when a user has changed any value in the textbox (or in a
dropdown) and then if he/she tries to leave the record without saving I want to give a save warning. Since I don't want set the isdirty flag if you for
example klick tab, certain F-buttons, arrows (up/down/left/right) etc I
tried to capture the keypress/keydown event and ignore specific keycodes.
Since there are several keycodes that should be ignored I was hoping there
is a better solution.

Must support IE6 and NN7+ (mozilla). Since the site is unicode compatible
the user may add chinese characters for example.

Regards
/Hans

Jul 23 '05 #3
Hans wrote:
Hi!

Does anybody of you have a good algorithm to capture when a value in a
textbox is changed? I'm using the keypress/keydown events but they seems <snip>

Most form elements have a defaultValue property (what the value would be
changed to if the form was reset).

Must support IE6 and NN7+ (mozilla). Since the site is unicode compatible
the user may add chinese characters for example.


Note that the defaultValue property doesn't work properly for hidden input
elements in Mozilla based browsers.

HTH

C.
Jul 23 '05 #4
Thanks I tested the onchange event but it did not fire but I now realize
that it fires when the control loses the focus and not for every keystroke.

Thanks
/Hans
Jul 23 '05 #5
Hi again. The onchange event does not seem to work if I inside a textbox for
example capture F12 which is setting the value in the textbox to some value.
When I tab to the next field the onchange event do not fire (i can of course
set the isdirty flag in the code that is capturing the return key). If I
type a value in the first textbox and then tab to the second the onchange
event fire. Is it something strange with my code of capturing the F12 button
or is the onchange not triggered if the value is changed by javascript code?
<html>
<body>
<script language="javascript" type="text/javascript">
function captureF12(evt)
{
var keyCode = evt.keyCode ? evt.keyCode : evt.charCode ? evt.charCode :
evt.which;
if (keyCode==123)
document.getElementById('a').value='Test';
return true;
}
</script>

<form>
<input type="text" id="a" onchange="alert('onchange has fired');"
onkeydown="captureF12(event);">
<input type="text" id="b">
</form>
</body>
</html>

Regards
/Hans

Jul 23 '05 #6
On Wed, 29 Sep 2004 14:01:08 +0200, Hans <so***@nospam.com> wrote:
Hi again. The onchange event does not seem to work if I inside a textbox
for example capture F12 which is setting the value in the textbox to
some value.
That's because F12 doesn't change the value.

On my browser (Opera), F12 brings up the Quick Preferences menu. I don't
think it does anything in IE or Mozilla.

Why do you think F12 is significant? None of the function keys should be.

[snip]
<script language="javascript" type="text/javascript">


The language attribute is deprecated and redundant. Don't use it. Just
stick with the (required) type attribute.

[snip]
--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #7
> That's because F12 doesn't change the value.
No I understand that it does not change the value but in my case I capture
the event and change the value by javascript. But obviously the onchange
event is not triggered.

On my browser (Opera), F12 brings up the Quick Preferences menu. I don't
think it does anything in IE or Mozilla. Yes that is why we use F12 to insert the username/timestamp in a field (from
the windows version of the application users are used to use F5 but that is
not a good key to use since it is used by many browsers to reload the page).

Why do you think F12 is significant? None of the function keys should be.

[snip]
<script language="javascript" type="text/javascript">


The language attribute is deprecated and redundant. Don't use it. Just
stick with the (required) type attribute.

Yes I know. We supported NN4.7x before this release so I had to stick with
the old language attribute.

Once again thanks for your help.

regards
/Hans
Jul 23 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1991
by: Johann Blake | last post by:
I have a form with a single textbox control which is bound to a DataRelation in a typed dataset. The textbox displays the name of the product depending on the language selected from a combobox....
2
4805
by: Alpha | last post by:
Hi, I have a window based program. One of the form has several textboxes and a datagrid. The textboxes are bind to the same dataset table as the datagrid and the text changes to reflect different...
1
13832
by: Feng | last post by:
I have a web form A that contains a TextBox. A pop up window started by my form A will return a value and put it into the TextBox. What I need to do is that when this happens (when the value gets...
8
2560
by: Ken Sturgeon | last post by:
I have a button inside a panel control. Apparently I can't expect VB to respond to the button's _Click event. How do I capture the click event? Thanks Ken
1
3589
by: Tomaz Koritnik | last post by:
I have an UserControl with a Textbox on it. TextBox captures keys (I assume via overridden ProcessCmdKey method) and doesn't pass them onto parent (by not calling base.ProcessCmdKey) therefore...
2
5010
by: TC | last post by:
Hello, I need to build a very simple text editor. The requirement is that the input screen should be divided into 'm*n' cells ('m' rows, 'n' columns, with each cell of a fixed size). Whenever...
2
2139
by: cjard | last post by:
Suppose: A TextBox is bound to a BindingSource, which is bound to a DataTable A BindingNavigator is used to alter the current row being looked at by the BindingSource (i.e. Nav's NEXT button is...
2
2084
by: Kev | last post by:
Hello world, I am trying to capture the latest entry into a text box by the user and then insert it in a separate text box. I must not be searching the right key words because I can only find...
6
3717
by: Tom P. | last post by:
I'm trying to make one of our perennial favorites - The Syntax Color Editor. (Mostly as a learning exercise). I'm wondering if there is a way to capture the Paint event of a textbox so I can...
0
7220
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7105
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
7308
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
7023
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
7479
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...
0
5617
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5037
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
4702
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
3178
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.