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: Randy Webb <HikksNotAtHome@aol.com>
Date: Mon May 01 2006 - 04:36:49 CEST

Matt Kruse said the following on 4/30/2006 5:11 PM:
> RobG wrote:
>> An alternative is to go through all the form controls and test if
>> their current value is the same as their default value. Where it
>> isn't, they've been changed.

Depending on your definition of "changed", that may not be entirely true
though. The simplest example would be a Select element. User chooses an
option, changes his mind, changes it back to the original choice. Was it
changed?

>> How you do the test depends on the type of element. Inputs of type
>> "text", "file" or "password" have a defaultValue attribute that is
>> their default value, so you can test their current value against that.
>
> This is the approach taken in my functions at
> http://www.mattkruse.com/javascript/validations/source.html
>
> I provide an isChanged() function that takes a reference to any input
> control and returns true or false. It relies on generalized getInputValue()
> and getInputDefaultValue() functions which work for any input type and are
> also useful on their own.
> There is also isFormModified() which loops through all form controls and
> calls isChanged() on each and also provides a few additional features.

You may want to rethink it depending on what "changed" is supposed to
mean. Whether it has been changed or its value has been changed.

-- 
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Received on Mon May 1 05:28:34 2006