H I O X INDIA
Javascript Tutorial
Google
Web hscripts.com
 HOME  ||  Scripts  ||  Purchase  ||  Tutorials  ||  Images  ||  Tools  ||  Directories 
  :-)  Send Page   :-)   Feedback   :-)   Register   :-)   Links   :-)   Support   :-)   Bookmarks :-)  
 Forums   Hosting   Internet Stats   Easy Calculation   FUN Games 

Java-Script Tutorial
Introduction
Variables
Operators
Statements
Loops
Functions
Objects
Arrays
Browser Objects
Form DOM
Ask Your Doubts
Feedback





Window Confirm Method


Topic

How to popup a message and get user confirmation in javascript?



Explanation

Object: Window

Method or Function: confirm(string)

Description: This method is used to interact with user by popping up a message window and getting a confirmation. It takes the message as argument. Then shows a popup dialog box with the message and two buttons "ok" and "cancel".

If user selects "ok" it returns true, else return false. We can get the returned value and do our action. Example: For an example we will popup a message. If the user confirms, we will set the size of a text field as 4 else 10.


Example Code:
<form name=tett>
<input type=text name=tf value="testing confirm function" size=20>
</form>

<script language=javascript>
var df = confirm(" can we change the size to 4");
if(df)
        document.tett.tf.size = 4;
else
        document.tett.tf.size = 20;
</script>

Result:


Explanation:
In the above example,
  • first we created a form named tett.
  • form containing a text and button.
  • in the javascript code, we popup a message using confirm function.
  • the return value is captured in the variable named df.
  • if user clicks "ok" df will be true and the if portion will be invoked and the size of text field is set to 4.



  •         Javascript (JS) is one of the most used languages in the world. Some times spelled as Java Script. Hope you enjoy this tutorial. Do send your feedback or suggestions on this javascript or java script tutorial. This is a copyright content.

    others

    privacy policy     license     sitemap
    © 2004-2005 HIOX INDIA - hioxindia.com

    Other Links