halibutfishfinder2
Technical User
Firefox Ignores My Confirm Box but IE OK.
Can anyone see where I am going wrong? My script is supposed to check for checked boxes, then request a confirmation before posting the form. I could probably fix this by not using the submit button but I need this to submit without Javascript if it's disabled.
Strange thing is it seems fine in IE7 but not in Firefox as it posts the form while the confirm box is up.
Thanks.
/*Informs the user if no check boxes are checked and asks confirmation before posting the form*/
function confirmdelete(formname,nothingmessage,confirmmessage)
{
//Count selected checkboxes
var formControls = document.formdelete.elements;
var c = 0;
for (var i = 0; i < formControls.length; i++)
if (formControls.type.toLowerCase() == 'checkbox'
&& formControls.checked)
c++;
//If no checkbox is selected
if (c==0)
{
alert(nothingmessage);
return false;
} else {
// entry is marked so show confirm option
var agree=confirm(confirmmessage);
if (agree)
{
//Submit the form
//return true;
document.forms[formname].submit();
}
else
return false;
}
}
And the function call...
<input name="delete" id="delete" type="submit" value="Yes" onmousedown="return confirmdelete('formdelete','You must mark an entry first','Are you sure you want to delete marked entries?')" />
Can anyone see where I am going wrong? My script is supposed to check for checked boxes, then request a confirmation before posting the form. I could probably fix this by not using the submit button but I need this to submit without Javascript if it's disabled.
Strange thing is it seems fine in IE7 but not in Firefox as it posts the form while the confirm box is up.
Thanks.
/*Informs the user if no check boxes are checked and asks confirmation before posting the form*/
function confirmdelete(formname,nothingmessage,confirmmessage)
{
//Count selected checkboxes
var formControls = document.formdelete.elements;
var c = 0;
for (var i = 0; i < formControls.length; i++)
if (formControls.type.toLowerCase() == 'checkbox'
&& formControls.checked)
c++;
//If no checkbox is selected
if (c==0)
{
alert(nothingmessage);
return false;
} else {
// entry is marked so show confirm option
var agree=confirm(confirmmessage);
if (agree)
{
//Submit the form
//return true;
document.forms[formname].submit();
}
else
return false;
}
}
And the function call...
<input name="delete" id="delete" type="submit" value="Yes" onmousedown="return confirmdelete('formdelete','You must mark an entry first','Are you sure you want to delete marked entries?')" />