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:
- Open two IE windows.
- Copy some values in the clipboard and paste on textBox1 in IE window 1.
- Then click on IE window 2.
- Go back to the IE window 1 by click on controls other than textBox 1.
- 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: javascript, onblur, onchange.
Trackback this post | Subscribe to the comments via RSS Feed