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 bkrike 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
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
 
Javascript validation, forum216 has a few faqs on the matter. Also you could search for posts made there by other members. Maybe "Empty field validation"
If that doesnt help, hit google for Javascript form validation. But maybe you'd be best starting at
~*Gwar3k1*~
"To the pressure, everything's just like: an illusion. I'll be losing you before long..."
 
One way would be to utilise the "onchange" event on each of your elements. Use this to update a global variable (or even keep a record of which elements have changed by adding them to an array). Here's some code you might find useful:

Code:
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;>
<html>
<head>
	<title>Detect Change</title>
<script type=&quot;text/javascript&quot;>
var changed=false;
function ElementChange() {
	alert(&quot;Change detected&quot;);
	changed=true;
}
function Validate() {
	if(changed) {
		alert(&quot;Something changed&quot;);
	}
	return false;
}
</script>
</head>
<body>
<form name=&quot;theForm&quot; onsubmit=&quot;return Validate()&quot;>
Name: <input onchange=&quot;ElementChange()&quot; type=&quot;text&quot; name=&quot;name&quot;><br>
Age: <select onchange=&quot;ElementChange()&quot; name=&quot;age&quot;>
		<option value=&quot;0&quot;><25</option>
		<option value=&quot;0&quot;>25-30</option>
		<option value=&quot;0&quot;>>30</option>
</select><br><br>
<input type=&quot;submit&quot;>
</form>
</body>
</html>

Hope this helps.

Pete.


Web Developer &amp; Aptrix / Lotus Workplace Web Content Management (LWWCM) Specialist
w: e: Pete.Raleigh(at)lclimited.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top