Re: How to check that a form has been changed
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.javascript archive

Re: How to check that a form has been changed

From: Thomas 'PointedEars' Lahn <PointedEars@web.de>
Date: Sun Apr 30 2006 - 22:40:43 CEST

Taras_96 wrote:

> How do you detect that a form element has been changed? This thread:
>
>
http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/9ae1c9d419264380/125a82c9be127790?lnk=st&q=checking+html+form++(updated+OR+edited+OR+changed)&rnum=28&hl=en#125a82c9be127790
>
> suggests that you attach onChange event handlers to every form element,
> and when the handler fires you update a global 'isChanged' variable.
> This technique seems to be a bit messy to me (I have many form
> elements), [...]

If we lived a perfect world, that would not be necessary. The `change'
event is specified to bubble by default, so you can handle that event on
the `form' element or any other parent element (even though it does not
have the corresponding attribute).

<URL:http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-eventgroupings-htmlevents>

Try

  document.forms[0].onchange = function() { alert(42); };

or

  document.forms[0].addEventListener(
    'change', function() { alert(42); }, false);

in Geckos, Operas and KHTML-based browsers. When you change a form control
(of the first form in the document, and focus another element after that),
you should see a message box showing "42".

However unfortunately, there is also IE, where it does not bubble, and where
therefore you cannot handle the event easily:

<URL:http://msdn.microsoft.com/workshop/author/dhtml/reference/events/onchange.asp>

PointedEars, with a fitting random signature

-- 
Bill Gates isn't the devil -- Satan made sure hell
_worked_ before he opened it to the damned ...
Received on Mon May 1 05:28:09 2006