Page 1 of 1

Confirmation Window

Posted: Mon Mar 08, 2004 8:40 am
by kendall
Hello,

I want to create a confirmation dialog window that will confirm or canel and action triggered by a "click on link" but im not too familiar with javascript and how this works ca somone show me an example

the link when clicked redirects the user to reload the page however i want to have a confirm window that can either stop or proceed the process...can this be done? did i explain myself clear?

Kendall

Posted: Mon Mar 08, 2004 8:44 am
by JayBird
just like this

THis code in your head tag

Code: Select all

<script language="JavaScript">
function confirm() &#123;
	if(confirm("Are you sure you want to do that?"))  &#123;
		document.location="some_other.php";
	&#125;
&#125;
</script>

Then you link

Code: Select all

<a href="javascript:confirm();">Confirm</a>
Mark

Posted: Tue Mar 09, 2004 1:39 pm
by Unipus
Bech's right, but if you do it this way you don't have to have the URL in your javascript function, which is a good thing:

Code: Select all

<a href="thispage.html" onclick="confirmation()">click</a>

function confirmation() 
&#123; 
   if(confirm("Are you sure you want to do that?"))  
   &#123; 
      return true;
   &#125;
   else
   &#123;
       return false;
   &#125; 
&#125;