Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Anything changed on the page

Status
Not open for further replies.

DeSn

Programmer
Nov 20, 2001
111
0
0
BE
Is there a way to know if anything has changed on the webpage? I mean if a field has received a value or a combobox has changed, anything at all?

This is my situation: I have a page with a lot of fields and a save-button. What I want to do: if nothing has changed on the page and the user presses 'save' I don't really want to go to the DB to save the data that hasn't changed.

I know I can compare the values of all the fields with the new values, but isn't there a way you can check the request or something like that, in one single test I mean?

Thanks
 
Why not add an onChange event to the form elements that sets a boolean variable to true when a field is changed? Then on submit you can check this boolean (assuming you have a javascript validate function).

Or you could set the value of a hidden field and test that server-side after form submission to determine if an update is required.

Just a few ideas,
Jeff
 
Another option you might wanna consider (which is what I did on a recent project of mine) is use BabyJeffy's idea, but instead of setting a boolean variable to see if anything's changed, instead load your page with the submit button disabled, and when anything is changed enable the submit button.

Another thing that you might wanna consider pertains to the onchange function. If the user is on your page and only modifies one text field the save button will not be enabled unless they move off the field first. (They can however click the disabled button, which will move off the text field, thus enabling the button. And as soon as the mouse button is released it activates the button. This gives the impression of clicking a disabled button which can be confusing for some users.) To remedy this situation you can use the onkeyup (or similar keypress event) for your text fields to activate the submit button. However, there is also a loophole in this. If the users are using the tab button to jump from field to field it will activate the submit button.

Anyway, this might give you some ideas to chew on.

-kaht

banghead.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top