AlfieWebDevTips Homefor new and experienced developers
[Home Home] [Web Development Web Development ] [Code Generators Code Generators ] [Resources Resources ] [Contact Us Contact ] |WebDevTips Privacy Privacy |
Print This Page

You are here : Home - Web Development - Javascript - Confirm Guide

Javascript Confirm Guide



Example confirm dialog

The confirm box is similar to the alert box in appearance but has 2 buttons. The main difference is that true or false is returned depending on the button pressed.

confirm icon

Confirm boxes contain an Icon with an ? similar to the one above. The title bar of the box varies according the the browser used and cannot be changed. the same applies to button text. You can have multiple lines of text using \n where the new line starts.

I should point out that the only real problem with confirm boxes is the button text. Depending on the platform/operating system, the buttons are named either
(OK = true - Cancel = false) or (Yes = true - No = false)

Due to the button text your question must be applicable for both eventualities.

Basic syntax for the confirm box looks like this
confirm("Your message");


Time for an example

open the confirm box

The Code

<script language="JavaScript" type="text/javascript"> 
<!-- 
function confirm_ex(){ 
if (confirm("Will I show an alert box\n\nOK=Yes - Cancel=No")){ 
alert("here is the message"); 


// -->
 
</script> 
<a href="#" onClick="confirm_ex();return false;">open the confirm box</a>

That's really all there is to know -
If true (OK or Yes) then do what ever you need to.
If false (Cancel or No) then do something else.

So in the final part we will put all of the boxes together in one demonstration:


intro | alert | prompt | confirm | final chapter





Google
 

[back to top of page]   

[labelled with icra -  - this link will open in a new window] [RSS Content]

[Copyright © WebDevTips]