Javascript: onchange problem

November 4, 2008 at 1:23 am Leave a comment

I have wrote some javascript to try synchronize the value from textBox1 to textBox2, and then added to the textBox1 in cs file like this:

String SyncValueScript = "document.getElementById('" + textBox2Control.ClientID +
"').value = this.value;";
textBox1Control.Attributes.Add("onchange", SyncValueScript);

However I found that there is a situation that onchange will not be fired, even the value of textBox1 is changed. Below is the step to reproduce this situation:

  1. Open two IE windows.
  2. Copy some values in the clipboard and paste on textBox1 in IE window 1.
  3. Then click on IE window 2.
  4. Go back to the IE window 1 by click on controls other than textBox 1.
  5. you will find that the value of textBox1 is not synced to textBox2.

Solution: there is a very easy fix for this problem, just use “onblur” event instead of “onchange”.

Advertisement

Entry filed under: Tech Share. Tags: , , .

SSIS: Custom File Logging Create context shortcut for Visual Studio msbuild

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


Recent Posts

Categories


Follow

Get every new post delivered to your Inbox.