Confirmation Window

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Confirmation Window

Post 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
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post 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
Unipus
Forum Contributor
Posts: 409
Joined: Tue Aug 26, 2003 2:06 pm
Location: Los Angeles, CA

Post 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;
Post Reply