473,659 Members | 2,609 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 2956
On Wed, 29 Sep 2004 12:12:21 +0200, Hans <so***@nospam.c om> 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.c om> 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="javas cript" type="text/javascript">
function captureF12(evt)
{
var keyCode = evt.keyCode ? evt.keyCode : evt.charCode ? evt.charCode :
evt.which;
if (keyCode==123)
document.getEle mentById('a').v alue='Test';
return true;
}
</script>

<form>
<input type="text" id="a" onchange="alert ('onchange has fired');"
onkeydown="capt ureF12(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.c om> 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="javas cript" 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="javas cript" 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
1998
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. When you select a different language, the textbox must show the name of the product in the selected language. This is done by setting the RowFilter property of the DefaultView on the table where the text comes from. If no text exists (that is, no...
2
4812
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 row selected in the datagrid. I want to save the changes that user make in the textboxes when they select a different row in the datagrid. I tried capturing the textbox.text at datagrid's CurrentCellChanged event but by then the textbox.text...
1
13852
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 into the textbox), capture this client side event and fires up a JavaScript function to do my stuff. I am having program to make this happen. I tried both HTML's "input" text box and ASP:TextBox and I tried "OnChange", "OnLoad", ... and none...
8
2573
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
3598
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 KeyDown is not trigered in parent UserControl. I wan't to catch enter key in UserControl but I can't do that. Is there any way to capture it before it reaches TextBox WITHOUT modifying TextBox code? regards Tomaz
2
5024
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 the user wants to input text, he will click on one of these cells, and then enter the text. The text should then be visible inside the cell. From my very limited knowledge of VB, I plan to use the 'group box' construct to denote one cell. Now,...
2
2147
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 pressed. BS.Position changes from 2 to 3, Textbox was showing APPLE, now shows ORANGE) Does the textbox receive any notification that this occurred? If so, what?
2
2092
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 oldvalue and value (which is the old value plus the inserted or changed value) It is the inserted or changed value that I want. I have tried Dim strControlName As String, strContValue As String, strContOldValue As String
6
3731
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 render the text myself. I've tried to replicate the functionality of a textbox, but I think it would be easier to simply take over the painting of a plain textbox. Then I wouldn't have to deal with several problem areas I'm currently running into.
0
8428
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8341
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8751
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8539
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8630
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7360
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4342
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2759
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 we have to send another system

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.