0

I know the HTML onChange event is triggered only when the element is blurred.

But is there a way to run a script when the content of a textbox changes? Even if it is changed in Javascript?

I have a textbox in my form to select a date. I also have a button with a calendar to pick a date. This calendar writes in the textbox and I want to do something when the date changes.

I cannot change the Javascript of the calendar.

I also want compatibility with all major browsers (IE7-9, Firefox, Chrome, Safari, Opera, ...).

4
  • Does the calendar have an event to let you know something was selected? Well written components do. Commented Oct 18, 2011 at 17:09
  • do you have a link to a demo? Commented Oct 18, 2011 at 17:18
  • @epascarello: No, there is no such events. Commented Oct 18, 2011 at 17:56
  • @GregThompson: I'm working in localhost for now, so I don't have any url to give you. Commented Oct 18, 2011 at 17:56

2 Answers 2

2

You're looking for mutation events (eg. DomAttrModified).

See Detect element content changes with jQuery if that would help you as a starter.

Sign up to request clarification or add additional context in comments.

3 Comments

I'm not sure how to use mutation events properly, can you give an example? Is it compatible with all browsers?
No, they're not cross-browser but rather "new" implementation. However I think there are readily-made plugins / scripts to behave like mutations would behave. I've seen at least jQuery Mutation Events plugin.
Thanks, but I cannot use jQuery in my project.
0

I found an answer to my question wich is maybe not the better one, but still works. It uses javascript timers.

function watchElement()
{
    var newVal = document.FormName.TextboxName.value;
    if(oldVal != newVal) {FunctionToCall();}
    oldVal = newVal;
}

var oldVal = document.FormName.TextboxName.value;
setInterval(watchElement, 500);

I know this is not the better code in the world, but it works for every major browsers.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.