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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Firefox Ignores My Confirm Box but IE OK

Status
Not open for further replies.

halibutfishfinder2

Technical User
Nov 30, 2007
2
GB
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?')" />
 
try this...

Code:
<input name="delete" id="delete" type="submit" value="Yes" onclick="return confirmdelete('formdelete','You must mark an entry first','Are you sure you want to delete marked entries?'); [COLOR=green]return false;[/color]" />

Cheers

nick
 
Many thanks nick,

it now works fine in both browsers and is unobtrusive - just how I like it.

Regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top