Displaying Confirm window for user input

var my_string = confirm("Are you sure ?");
The confirm box will return TRUE if the OK button is clicked and it will return FALSE if cancel button is clicked.

This confirm window will have two buttons, one for OK and other for CANCEL. Visitor can click one if the two buttons and the user action can be captured by assigning this to a variable.

We check the return value by using if else condition checking

We can further improve this by linking the returned value of the confirm button to an alert window.
DEMO of window confirm
Here is the code for a confirm box linked to an alert window.
<title>Demo of Confirm window in JavaScript</title>

<script type="text/javascript"> 
function show_confirm() { 

var my_string = confirm("Are you satisfied with the quality of the tutorials here?");
if(my_string){alert("Thank you");
alert("Please use the contact us page to give your feedbacks");}


<input type=button value='Click here to display confirm Window' OnClick="show_confirm()">

Using document.write()

DEMO of window confirm using document.write()
<script type="text/javascript"> 
function show_confirm() { 
var my_string = confirm("Are you sure ?");
document.write("You clicked OK ");
document.write("You clicked Cancel ");
document.write("<br><br>Back to <a href=window-confirm-demo2.php> Demo  Page </a>");
document.write("<br><br>Back to <a href=window-confirm.php> Window Confirm Page </a>");
<input type=button value='Click' onClick=show_confirm()>

On confirmation submit or redirect page with parameters

Confirmation is taken before a delete opration. Here the id of the record is submitted to a page ( redirected ) with additional parameters through query string based on the confirmation of the user.
function show_confirm(c_id) { 
var my_string = confirm("Are you sure, want to delete ? ");
We can use the link to delete here.
<input type=button value='Delete' 
Window object Reference Window close Passing data from Child window to parent window
Subscribe to our YouTube Channel here


* indicates required
Subscribe to plus2net


    Post your comments , suggestion , error , requirements etc here

    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer