Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

onChange event not executing 1

Status
Not open for further replies.

calverlt

Programmer
Nov 29, 2000
3
US
Scenario: User enters a new value into a text field. Upon tabbing out of the field the onChange event is fired which calls a function. Validation within this function checks the entered value. If the value isn't valid an alert is executed and the value is set to 0. If the user now enters the same value as before the onChange event does not fire and so the invalid value can be accepted.

The question is: Why doesn't the onChange event fire, given the fact the value of the field is set to 0 in the function? I have tried setting '.defaultvalue' with no success.
 
Use the onBlur event instead. I'm not sure why this happens, but I tested it in IE5.5 and it does not fire the onchange event. jared@aauser.com
 
if the user enters the SAME value then the onchange sure won't fire
try using onblur instead
it is fired just after the onchange
let me know - but it should work just the same !
 
if the user enters the SAME value then the onchange sure won't fire
try using onblur instead
it is fired just after the onchange
let me know - but it should be working !!!
 
jaredn - Thanks for the suggestion.
iza - The value shouldn't be the SAME because it is being set in the validation function to zero, hence when the user enters the same text as before they are changing the value from zero to something else.

The onBlur method does execute every time the object loses focus, however this is not ideal because the user can tab through a large number of fields which all use the same validation function, which would consequently be called many times.
 
right, but the event will never b fired if the value is the same, so the validation function will never b called ... that's why it's useless to change the value IN the validation function
you can set a default value for the text box tho : either in the body.onload or in the the html tag (<input type=text name=whatever value=&quot;default one&quot;>) but if the user doesn't reload the page and enters the same value then the onchange won't fire ...
that's why i guess the onblur is better, even if it may call a bit too often the validation function
why don't you have only one big validation function for the whole form, that is called just once (with onsubmit) ?
 
Thanks for your help iza, I understand what you're suggesting, and may have to bite the bullet and redevelop the structure of this pages validation functionality (the problem, as always, being the fact that someone else developed the page and I'm simply trying to fix their bugs!!). Thanks, Tom.
 
yes, i know about fixing someone else's bug, especially when there's no comment at all and crappy coding ... and often i find it faster to redevelop all by my own, but i don't know if it's really wise ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top