473,379 Members | 1,174 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Simple way to check if form elements have changed

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
6 15324
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Will | last post by:
Hi, I have a problem trying to validate dynamically created html form elements using javascript. I have dynamically created a check box using ASP for each record in a recordset and have given each...
5
by: Richard Cornford | last post by:
I am interested in hearing opinions on the semantic meaning of FORM (elements) in HTML. I have to start of apologising because this question arose in a context that is not applicable to the...
2
by: Mark Hannon | last post by:
I am trying to wrap my brain around storing form elements inside variables & arrays before I move on to a more complicated project. I created this simple example to experiment and as far as I can...
2
by: jingalls | last post by:
I'm trying to modify a form so that when a user clicks a checkbox for a shorter version of the form, it will replace swap the default (long) form elements with the short version of elements, so...
2
by: msforme | last post by:
Hi , Is there some way by which I get to know if the state of my form elements have changed or not ? I mean If I have to save data which has been entered by user in the screen, Is there some way...
3
by: dan | last post by:
I am a bit of a java newbie so please forgive me. I am trying to do a simple check-all / un-check-all checkbox system. All of the solutions I have seen use "this.form.elements.length" or a...
11
by: shankwheat | last post by:
I have a function which passes text from txtdebt to debtsbox which works fine. However, I want to add code which examines the value of debtsbox and if any of the values the user entered contain the...
2
by: mars123 | last post by:
hi, I am facing a js error in my code, below is the prob. statement I have a radio2 javascript function as below, it works like this.. When a parent radio button is selected only one of its...
3
by: mattennant | last post by:
Hi There I'm fairly new to javascript, and have been looking for a way for a user to add form elements (text area) by clicking a form button I happened upon a script submitted on this site ...
5
by: Rider | last post by:
Hi All, Here is the reason why i ak asking for ur help. I have a edit form in which the values already stored in DB are populated. User can edit some or all the values in the form. then he...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.