Confirmation Boxes using JavaScript, JavaScript Tutorial, Global Guide Line Technology.
Bookmark Bookmark: Confirmation Boxes using JavaScript, JavaScript Tutorial Forum | Blog |

      Home                    

Basic JavaScript Guide.
 JScript Introduction.            
 JScript Why?                       
 JScript Recognitions.          
 JScript onMouseover.         
 JScript with Buttons.           
 JScript Alerts.                     
 JScript Variables.               
 JScript Operators.               
 JScript Functions.               
 JScript Prompts.                 
 JScript Conditions.             
 JScript Validations.            
 JScript Confirmation Boxe
 JScript Browser Detection.  
 JScript Redirection.            
 JScript on Links.                 
 JScript Switch.                    
 JScript Loops.                     
 JScript Events.                    
 JScript Exception Handling.
 JScript Reserve Characters. 
 JScript with Objects.            
 JScript Math Object.           
 JScript using Dates.             
 JScript using String.            
 JScript using Arrays.            
 JScript Operations.              
 JScript Handling Cookies.   
 JScript in Mapping.             
 JScript Time Out.                
 JScript Summary.                

JavaScript Tutorial >> Confirmation Boxes using JavaScript.


     Back             Next     


JavaScript confirmation boxes can be a handy way to give our visitors an alternative of whether or not an action is performed. JavaScript confirmation box will pop up much like an JavaScript alerts, but will allow the viewer to press an "OK" button or "Cancel" button. Here is the necessary command for creating a confirmation box.

Syntax for JavaScript Confirmation Boxes

confirm("JavaScript Confirmation Box statement, Press OK or Cancel");

The difficulty is, if we use just that it isn't very handy to reuse of capture the user action. The JavaScript confirmation boxes will return a value of True or False, so this is what we must use to make use of the JavaScript confirmation box. An easy way to get the value for later use is to assign it to a JavaScript variable, like the below code for JavaScript Confirmation box capturing the returned value. 

Capturing JavaScript Confirmation Response

var respOfConfirmation= confirm("Press OK or Cancel.....");

Now, here we can use the respOfConfirmation a JavaScript variable to examine what the visitor responding to this JavaScript alert.  Here action is depending on the value the JavaScript confirmation box returned on behalf of user action. We can do this with an if/else statement block like below code we are handling JavaScript Confirmation response using JavaScript conditional statement [if/else].

Handling JavaScript Confirmation Response using if/else

<SCRIPT language="JavaScript">
function Confirm_Ok_Cancel()
{
 var respConfirmation= confirm("Please Press Ok or Cancel...");
 if (respConfirmation== true)
 {
   alert("Hi you pressed Ok, I got it with JavaScript Confirmation response...");
 }
 else
 {
  alert("Hi you Pressed Cancel, Have a nice tour of JavaScript Tutorial");
  }
}
</SCRIPT>

Now use the above JavaScript Confirmation box, its capturing and handling code in the body of our web page like this.

<body onLoad="Confirm_Ok_Cancel()">

Out put of JavaScript Confirmation Boxes.

When the page will be loaded or refreshed then visitor can have the below screen shore in front of him.



     Back             Next     
 

JavaScript Alert, Confirmation and Prompt Boxes Examples



[ About ] [ Contact ] [ Home ]
[ Links ] [ Site Map ] [ Services ] [ Privacy ]

Copyright 2005 -  2018 www.globalguideline.com All rights reserved. (Best viewed in IE 6.0+ or Firefox 2.0+ at 1024 * 768 or higher) 220 visitors are online now