# Solved: input type=submit and javascript



## andynic (May 25, 2007)

Hi,

The bottom line of this post:
Is there a simple way to have a javascript funciton abort a submit?

I have a form with the following form definition:
"

The form contains the following input tags:

The displayed page contains multiple rows of data. The user can make direct updates to the data. 
Certain buttons on the page, like the submit button shown above, send the user to a new page. (In
the case of the button shown above, in order to create a new record.)

The hidden value of the input tag named 'DISP_MGchangedDataFlag' (see "onclick" above) gets 
set to "DATA_CHANGED" if the user changes any data in the form.

If the user has made changes, the function "checkForDataChange" (see onclick above and code below) 
puts up an alert telling the user to commit the changes first.

However, the code below, as written, allows the form to continue the submit rather than staying
on the current page.

What can I add to the code after the call to "alert" to keep the form on the current page?
function checkForDataChange(eltId)
{
var fldToChk = document.getElementById(eltId);
if ( fldToChk.value == "DATA_CHANGED" )
{
alert ("relevant message telling the user to commit changes first");
// this does not work: window.document.execCommand('Stop');
// this does not work: document.manageGalleries.abort();
// this does not work: document.manageGalleries.exit();
}
}

Thanks for your help,
Andynic


----------



## andynic (May 25, 2007)

Found the solution:
Write the with onclick like this:

Write the function checkForDataChange like this:
function checkForDataChange(eltId)
{
var fldToChk = document.getElementById(eltId);

if ( fldToChk.value == "DATA_CHANGED" )
{
alert ("relevant warning message");
return false;
}
else
{
return true;
}
}


----------



## andynic (May 25, 2007)

NB: The above is tested in Safari only.


----------

