tags:

views:

89

answers:

3

Hello, I'm trying to create a alert box which prompts user whether to delete or cancel, when I'm clicking on delete button it is working fine but when I click cancel again my webpage is closed. Below is the enclosed function. Please help.

<SCRIPT language="JavaScript">
<!--
function go_there()
{
    var where_to= confirm("Do you really want to go to this page??");

    if (where_to== true)
    {
        //closes the page
    }
    else
    {
        //Cancel the page and do not close the page
    }
}
//-->
</SCRIPT>
+2  A: 

In such cases the most common error might be that you would have omitted

return false

on clicking cancel, it should return false. This might be a plausible solution. In your case either give a return statement or define an empty function which does nothing.

Saeros
Thanks Saeros...It Worked for me.Thanks
pradeep
A: 
<SCRIPT language="JavaScript">
<!--
function go_there()
{
    if (confirm("Do you really want to go to this page??")) {
        //closes the page
    } else
        return false;
}
//-->
</SCRIPT>
Kirtan
A: 
<script language="JavaScript">
<!--
function go_there() {
    if(!confirm('Do you really want to go to this page?')) {
        return false; //Cancel the page and do not close the page
    }
}
-->
</script>
Callum