PDA

View Full Version : return false does not work in firefox?



monaya
02-11-2009, 06:52 PM
I have simple javascript as such to confirm an onClick event before processing:

Firefox processes whether you click OK or CANCEL??


<script LANGUAGE="JavaScript">
<!--
function confirmSubmit()
{
var agree=confirm("Are you sure you want to delete?");
if (agree)
return true ;
else
return false ;
}
// -->
</script>

<a href="page.htm" title="delete" onClick="return confirmSubmit()">

jscheuer1
02-12-2009, 01:18 AM
The way that code should work (given no other scripts that would conflict or otherwise affect the outcome) in any browser is, if someone confirms, then page.htm will be loaded into the current base window (usually the current window). If they do not confirm, no change in the current page should occur.

But, there is no real link in your code:



<a href="page.htm" title="delete" onClick="return confirmSubmit()">

With only that, there is no closing </a> tag and no text or image to click on to activate it.

If you do:


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

</head>
<body>
<script LANGUAGE="JavaScript">
<!--
function confirmSubmit()
{
var agree=confirm("Are you sure you want to delete?");
if (agree)
return true ;
else
return false ;
}
// -->
</script>

<a href="page.htm" title="delete" onClick="return confirmSubmit()">Huh</a>
</body>
</html>

Then it works just as I predicted in FF.

What exactly is happening?

Please post a link to the page on your site that contains the problematic code so we can check it out.

Note: The language attribute for the script tag is deprecated, and the type attribute is required.

smansakra
02-12-2009, 01:38 AM
hi, monaya, i suggest you to use firefox and install firebug addon... so if your script error, you will get "why your script is error.."

OK ?

monaya
02-12-2009, 03:41 AM
Hmm yes that does work. Thank you!!