difrad76
12-16-2005, 09:47 AM
I have to make sure that form data has been saved. In order to do that I need to force users to populate the form.
I thought to use onBeforeUnload event to do just that. So if the form is being closed it would fire a validateForm() function. Depending on the returning value I want either just close the window or display alert about errors and abort closing window.
When I do that the onBeforeUnload event throws a dialog box where user can confirm closing.
Is there any way to avoid this dialog box all together and just act on what the validateForm() functions returns ?
This is my code
function validateForm()
{
var date1=document.getElementById("date_month").value;
var hour1=document.getElementById("hour").value;
var min1=document.getElementById("min").value;
var ampm=document.getElementById("ampm").value;
var error="";
if (date1=="")
error+="Please select a date !\n";
if (hour1=="")
error+="Please select a hour !\n";
if (min1=="")
error+="Please select a minutes !\n";
if (ampm=="")
error+="Please select a AM/PM identifier !\n";
if (error!="") {
alert (error);
return false;
} else {
window.close();
return true;
}
}
<body onbeforeunload ="return validateForm()">
Thanks
I thought to use onBeforeUnload event to do just that. So if the form is being closed it would fire a validateForm() function. Depending on the returning value I want either just close the window or display alert about errors and abort closing window.
When I do that the onBeforeUnload event throws a dialog box where user can confirm closing.
Is there any way to avoid this dialog box all together and just act on what the validateForm() functions returns ?
This is my code
function validateForm()
{
var date1=document.getElementById("date_month").value;
var hour1=document.getElementById("hour").value;
var min1=document.getElementById("min").value;
var ampm=document.getElementById("ampm").value;
var error="";
if (date1=="")
error+="Please select a date !\n";
if (hour1=="")
error+="Please select a hour !\n";
if (min1=="")
error+="Please select a minutes !\n";
if (ampm=="")
error+="Please select a AM/PM identifier !\n";
if (error!="") {
alert (error);
return false;
} else {
window.close();
return true;
}
}
<body onbeforeunload ="return validateForm()">
Thanks