• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem with on change event

 
Anupreet Arora
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Please chk out out this simple html file code. The problem that is coming in IE is that if I change the value in the text box to say 1001 and press tab, onchange evnt is called and I see an alert and the value changes to 100. If I again change this value to 1001 and press tab, now the onchange evnt is not called, whereas it should have been!! The behaviour is normal in netscape but not in IE.
Kindly suggest a work around as I am stuck with this.
I can't use onblur because there would be proble, setting focus to the next field in my actual application
<html>
<head>
<title>Untitled</title>
<script language="JavaScript1.2">
function changed(fieldObj)
{
alert(fieldObj.name);
fieldObj.value = 100;
}
</script>

</head>
<body>
<form>
<input type="Text" name="inputField" value="100" onchange="changed(this)">
</form>
</body>
</html>
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
urgent in your title is not going to help you out here
you might want to use onblur
 
Joe Coggins
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had a problem running your code in IE, so I used an Id instead.

<html>
<head>
<script type="text/javascript">
function change1() {
//document.forms[0].f2.value="222";
document.forms[0].f2Id.value="222";
}
function change2() {
alert("in");
}
</script>
</head>
<body>
<form>
<input type="text" id="f1Id" name="f1" onchange="change1()"/>
<input type="text" id="f2Id" name="f2" onchange="change2()"/>
</form>
</body>
</html>
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please read this: http://www.coderanch.com/how-to/java/EaseUp

You should use onblur and not onchange.
If you do not want the user to change the value, the field should be readOnly. BUT just an FYI, setting it to readonly is just a fake security, anyone can change the value with debuggers, you should always check it on the server.

Eric
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic