Forums

Check for changes to input fields

agc 21 Sep, 2010
Hello,

I've done lots of searching but am perhaps searching for the wrong thing!

I have a bunch of pages built using Chronoform which are essentially data capture pages which write straight to tables.They also allow updates to be made after the initial saves.

I'd like to highlight to users that they have altered/entered data but not yet saved it.

I anticipated using 'onChange' to set a flag for each of the fields and then 'onUnload' to check if the flag was set and if so then write an alert to the user.

Is there an accessible way to do the onUnload for the forms given that the <body> tag can't be used in the form code panes? Or some other way to achieve the same goal?

Hopefully someone can point me in the correct direction.

Thanks

Alan
nml375 21 Sep, 2010
Hi Alan,
I'd recommend that you look at the Event-engine provided by MooTools. Something like this should do the trick:
<?
$doc =& JFactory::getDocument();

$script = '
function handleUnload(event) {
  var e = new Event(event);
  e.stop();
  //Rest of code goes here...

}

window.addEvent("domready", function() {
  document.body.addEvent("unload", handleUnload);
});
';

$doc->addScriptDeclaration($script);
?>


The PHP-part is used to add the script to the page head rather than inline body, and the "domready" event is used to add the onUnload-event only as the page is completely loaded..

/Fredrik
agc 21 Sep, 2010
Many thanks for the pointer. I shall try it out tomorrow.


Alan
This topic is locked and no more replies can be posted.