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!

Check if any Form Elements have changed?

Status
Not open for further replies.

fixthebug2003

Programmer
Oct 20, 2003
294
US
Hi,
Is there a way to check if a user has changed data in any of the form elements (like INPUT type="text" and ListBoxes or checkboxes) without having a onchange event on each of these form elements...?
Like a user could have changed data in a text box, or selected a check box or picked a different option in the listbox.....all I want is a generic way of trapping any of these changes and mark the page dirty...so I can prompt the user before he leaves the page whether he wants to Save his changes before he leaves?

Thanks
Fixthebug2003
 
Is it possible to use a flag? Define a global variable flag=0, set flag=1 in onChange events, check this flag as soon as user leaves.
 
Try the following for text fields and textareas etc.
It might contain errors, I've typed it dirrectly here.
For dropdowns and radio buttons use the onchange.

[blue]
<script>
var isChanged = false;
var oldValue;
function saveOldValue(obj)
{
oldValue = obj.value;
}

function checkForChange(obj)
{
if (obj.value != oldValue) {
isChanged = true;
// do something
}
}
</script>

<input type="text" onFocus="saveOldValue(this)" onBlur="checkForChange(this)">
[/blue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top