Window Confirm Method
: WindowMethod or Function
: 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.
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.
<input type=text name=tf value="testing confirm function" size=20>
var df = confirm(" can we change the size to 4");
document.tett.tf.size = 4;
document.tett.tf.size = 20;
In the above example,
- first we created a form named tett.
- form containing a text and button.
- 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.