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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

onChange doesn't fire when control changed by Javascript

Status
Not open for further replies.

hughesai

Technical User
Aug 1, 2002
101
GB
Hi all,

I have a input text box used for dates. If a date is typed I have some Javascript validation on it. I also have a button which opens a Javascript calendar in order to pick a date and populate my text box. However, by definition onChange does not recognise this as a change (it only picks up user changes).

I want to be able to recognise that the text box contents have changed in order to validate them. I don't want to add the validation to the javascript calendar becasue it is generic and I use it in other places.

Is there an event which recognises changes to an element made by scripting from another page? I'm using IE and my application doesn't need to run on other browsers.

Thanks

hughesai
 
hmm...

what about changing your onchange() to an onblur(), and then changing your commonly-used popup window to set focus on the text box, then enter the value, then blur focus of the textbox?



*cLFlaVA
----------------------------
[tt]your mom goes to college[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
[banghead]
 
cLFlaVA - I tried your suggestion, but it was not sucessful. The validation still does not fire.

Dan - The calendar is generic and is used in other places. Some of these need validation, some don't, and the event handlers are different in any case. I, therefore, can't call specific handlers from the calendar.

Is there a way of forcing an event to fire from code or a specific event that reacts to a change made by code.

hughesai


 
I find that setting an empty (yet named) function is a handy way to do this. In the "generic" code define some empty function(s) and call them at certain points in your code. They are empty, so they will do nothing.

On a page where you need to "add some code", you can re-define one of the functions on the page... so that when the "generic" code runs, it now calls a function that has content.

Does this make sense?

Cheers,
Jeff

[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top