Verify Changed Items

B

Bob Rivers

Hi,

Is it possible to verify, using js, if ANY item in a form has changed?

For example: I have a <form> with multiple items (<input>, <select>,
<textarea>, etc). I need to track if one (or more) of this items has
changed by a user.

One option, is to put a onChange event in each one of these fields
and, if the event occurs, I will update a hidden input to indicate
that something changed on the form.

But, the problem is that my form is big, and I was wondering if I
could check this situation by invoking something like
if(document.form[0].changed)...

Is it possible?

TIA,

Bob
 
K

kaeli

Hi,

Is it possible to verify, using js, if ANY item in a form has changed?

Yes.

For example: I have a <form> with multiple items (<input>, <select>,
<textarea>, etc). I need to track if one (or more) of this items has
changed by a user.

One option, is to put a onChange event in each one of these fields
and, if the event occurs, I will update a hidden input to indicate
that something changed on the form.

But, the problem is that my form is big, and I was wondering if I
could check this situation by invoking something like
if(document.form[0].changed)...

Is it possible?

No, not like that.
Before the user does anything, have the script loop through the form
elements and save the values to an array or other structure (I'd use an
array and make the index be the same as the form element index for easy
compare later). When the user goes to submit or when you want to check,
loop again and compare the values.

That's assuming there is a reason you don't want to just use onChange.
Using onChange will not catch if a user changes a value then changes it
back to its original value (thus it wasn't really changed).


-------------------------------------------------
~kaeli~
The secret of the universe is @*&^^^ NO CARRIER
The more ridiculous a belief system, the higher
the probability of its success.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
-------------------------------------------------
 
B

Bob Rivers

Hi,

Is it possible to verify, using js, if ANY item in a form has changed?

For example: I have a <form> with multiple items (<input>, <select>,
<textarea>, etc). I need to track if one (or more) of this items has
changed by a user.

One option, is to put a onChange event in each one of these fields
and, if the event occurs, I will update a hidden input to indicate
that something changed on the form.

But, the problem is that my form is big, and I was wondering if I
could check this situation by invoking something like
if(document.form[0].changed)...

Is it possible?

TIA,

Bob

Just for the archive collections...

I received two good sugestions: one from Jim that controls the events
that have occured in the form.

And another solution from Kaeli that suggests to store the field
values into an array, using the onLoad and then when I leave the page,
compare the values againg with the one stored.

I decided to use Jim's solution.

Thanks everybody,

Bob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,079
Messages
2,570,573
Members
47,205
Latest member
ElwoodDurh

Latest Threads

Top