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.
>
>
>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
Thanks.