Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to tell if ANY form fields have changed

40 views
Skip to first unread message

jtub...@my-deja.com

unread,
Oct 16, 2000, 3:00:00 AM10/16/00
to

Is there any way to tell if ANY fields on a form have changed? I don't
see any form property that would tell me this.

Details:

I have a form with a submit button (which will effect a database
update) AND some other buttons on the same form that go elsewhere in
the system. What I want to do is if the user clicks one of the other
buttons (instead of the submit button), I want to check to see if any
of the form fields have changed. If so, they I will display an alert
to require them to click "Submit" before clicking the other buttons.

The only way I can think to do this is to put an "ohchange" event on
each field that sets an indicator; then I can check this indicator
when one of the other buttons is clicked.

But...I was hoping for maybe something a bit cleaner.

Any suggestions?

Thanks


Jeff


Sent via Deja.com http://www.deja.com/
Before you buy.

Greg Griffiths

unread,
Oct 16, 2000, 3:00:00 AM10/16/00
to
you could print the original above and then allow them to enter new data
into empty fields, checking this would be easier ? although writing the
same info back in to the database should not really be that much of an
issue ?

Bob Novell

unread,
Oct 16, 2000, 3:00:00 AM10/16/00
to
On Mon, 16 Oct 2000 17:26:20 GMT, jtub...@my-deja.com wrote:

>
>
>Is there any way to tell if ANY fields on a form have changed? I don't
>see any form property that would tell me this.
>
>Details:
>
>I have a form with a submit button (which will effect a database
>update) AND some other buttons on the same form that go elsewhere in
>the system. What I want to do is if the user clicks one of the other
>buttons (instead of the submit button), I want to check to see if any
>of the form fields have changed. If so, they I will display an alert
>to require them to click "Submit" before clicking the other buttons.
>
>The only way I can think to do this is to put an "ohchange" event on
>each field that sets an indicator; then I can check this indicator
>when one of the other buttons is clicked.
>
>But...I was hoping for maybe something a bit cleaner.
>
>Any suggestions?
>
>Thanks
>
>
>Jeff
>
>
>Sent via Deja.com http://www.deja.com/
>Before you buy.

The onChange IS the cleanest way to do it.

However, only textarea and selects support onChange, according to the
Netscape Client-Side Javascript Reference which I just checked.

Specify onChange="globalChanged=true"

Define globalChanged globally and set it to false

var globalChanged = false

Test the value, if it's true, they changed something.

This method of knowing if anything has changed is a widely used method,
in all programming languages.

I use it regularly in all sorts of programs to determine if the user has
made changes and warning them about if they ask me to close the document
or whatever has been changed.

You know "The document you are working on has changed. Do you want to
save the changes?"

Do you use VB? -
"One or more files in the project have changed. Do you want to save the
changes now" YES NO CANCEL

Happens ever time you hit the F5 key to run a program if you've modified
some of the source code or form data. I'm pretty sure they are just
using a global variable which gets set any time something is changed.

By the way - the documenation says that the onChange event occur when
the object looses the focus and it has changed.

So, this event won't fire everytime a user types a letter into a
textarea, just when they leave the textarea via the mouse or the tab key
- like when they click one of your buttons.

Bob

jtub...@my-deja.com

unread,
Oct 17, 2000, 3:00:00 AM10/17/00
to
Thanks for the replies. Apparently the onChange handler IS the only
way to check if something has changed as you said. I guess I was just
hoping that, since this is such a common thing to do, that maybe there
was a form property somewhere that would tell me that. I mean, the
form (well at least the element) object has to know that it was
changed, otherwise it couldn't run the onchange handler. Oh well, just
lazy me! I'll just code for it!

Thanks.

0 new messages