Displaying Confirm window for user input

We can display a confirm box to the visitor and ask their opinion. 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.

The confirm box will return TRUE if the OK button is clicked and it will return FALSE if cancel button is clicked.
var my_string = confirm("Are you sure ?");
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.
<html>
<head>
<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");
}else{
alert("Please use the contact us page to give your feedbacks");}
}
</script>

</head>
<body>

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

Using document.write()

DEMO of window confirm using document.write()
<script type="text/javascript"> 
function show_confirm() { 
var my_string = confirm("Are you sure ?");
if(my_string){
document.write("You clicked OK ");
}else{
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>");
}
</script>
<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.
<script> 
function show_confirm(c_id) { 
var my_string = confirm("Are you sure, want to delete ? ");
if(my_string){window.location="list.php?todo=del&c_id="+c_id;}
}
</script>
We can use the link to delete here.
<input type=button value='Delete' 
OnClick='show_confirm(2)'>
Window object Reference Window close Passing data from Child window to parent window

Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com







    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-2021 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer