• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

problem with on change event

 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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>
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
urgent in your title is not going to help you out here
you might want to use onblur
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please read this: https://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
 
Roses are red, violets are blue. Some poems rhyme and some don't. And some poems are a tiny ad.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic