By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,969 Members | 1,767 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,969 IT Pros & Developers. It's quick & easy.

Simple way to check if form elements have changed

P: n/a
I have a form with many fields... the fields are getting values from a
database.

I've tried onunload to just submit the form regardless of changes or
not but onunload and submit isn't working for me. Now I need some
type of event that will fire when a user tries to navigate from a page
to check to see if anything has changed and if so prompt them
(confirmation) to take action or not.

I know that the reset button only takes away anything that was added
to fields after the load so there must be some way to use the logic of
reset to simply check to see if fields have changed, right?

I need some help on this thanks.

Oct 12 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
wrote on 12 okt 2007 in comp.lang.javascript:
I have a form with many fields... the fields are getting values from a
database.

I've tried onunload to just submit the form regardless of changes or
not but onunload and submit isn't working for me. Now I need some
type of event that will fire when a user tries to navigate from a page
to check to see if anything has changed and if so prompt them
(confirmation) to take action or not.
Wrong idea to trust onunload and alike.

"navigating from a page" can mean tripping over the mains cord,
or pressing ctrl-alt-del.

If you want to secure changes in the page on a serverside database,
do so directly by AJAX or by refreshing[+formpost] the page.
I know that the reset button only takes away anything that was added
to fields after the load so there must be some way to use the logic of
reset to simply check to see if fields have changed, right?
Ever tried this, btw?

<input
value='myDefault'
onchange=
'if (this.value!=this.defaultValue)
alert("Changed")'>

effect appears only on blurr.

I need some help on this
Could never have guessed that.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Oct 12 '07 #2

P: n/a
On Oct 12, 11:34 am, roje...@gmail.com wrote:
I have a form with many fields... the fields are getting values from a
database.

I've tried onunload to just submit the form regardless of changes or
not but onunload and submit isn't working for me. Now I need some
type of event that will fire when a user tries to navigate from a page
to check to see if anything has changed and if so prompt them
(confirmation) to take action or not.

I know that the reset button only takes away anything that was added
to fields after the load so there must be some way to use the logic of
reset to simply check to see if fields have changed, right?

I need some help on this thanks.
Never tried it but according to the MSDN, input elements have a
defaultValue property. This might help you out:
http://msdn2.microsoft.com/en-us/library/ms535841.aspx

Oct 12 '07 #3

P: n/a
You could have a script that:
* attached a function to the onchange event for each input...
* The function could add to an array the id of the changed
input.
* Later, you could check the array's length to see if any
data had changed.
* If it had, use docuemnt.getElemenyById and the ids in the
array to gather the data from each input.

For this kind of excercise, the usual concern applies: none of this
code will work if javascript is disabled.

Oct 12 '07 #4

P: n/a
I've gotten it to work.... the submit onunload event. It's what the
client wants so mpmh
Solution I couldn't have the submit button named submit... go figure
-rlr

Oct 12 '07 #5

P: n/a
ro*****@gmail.com wrote:
I've gotten it to work.... the submit onunload event. It's what the
client wants so mpmh
Solution I couldn't have the submit button named submit... go figure
It masks the form's submit method. You should never name a sumbit
button "submit".

--
Rob
"We shall not cease from exploration, and the end of all our
exploring will be to arrive where we started and know the
place for the first time." -- T. S. Eliot
Oct 13 '07 #6

P: n/a
ro*****@gmail.com wrote:
I've gotten it to work.... the submit onunload event. It's
what the client wants so mpmh
Be very careful with this. If a page is navigating you may get away with
triggering a submit from an unload event and so effectively cancel the
navigation. But if a browser is being closed down it may still trigger
an unload event but may decide that there is no point in making any
additional HTTP requests (so no point in attempting to submit anything).
If you effectively train the users to expect their changes to be saved
automatically when they navigate they will also gain the expectation
that their changes will be saved automatically when they close the
browser down. If you cannot satisfy that expectation then you should not
encourage it.
Solution I couldn't have the submit button named
submit... go figure
And because you decided to keep your code to yourself it was not
possible for anyone to point out that very common mistake:-

<URL: http://jibbering.com/faq/faq_notes/f....html#faComMis >

Richard.

Oct 14 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.