Page 114 - DCAP202_Fundamentals of Web Programming
P. 114
Unit 8: Programming Constructs in JavaScript
If the user clicks on OK button the window method confirm() will return true. If the user clicks on Notes
the Cancel button confirm() returns false. You can use confirmation dialog box as follows:
<head>
<script type=”text/javascript”>
<!—
var retVal = confirm(“Do you want to continue ?”);
if( retVal == true ){
alert(“User wants to continue!”);
return true;
}else{
alert(“User does not want to continue!”);
return false;
}
//—>
</script>
</head>
Task Compare and contrast Alert dialog box and Confirmation dialog box.
8.4.3 Prompt Dialog Box
The prompt dialog box is very useful when you want to pop-up a text box to get user input. Thus
it enable you to interact with the user. The user needs to fill in the field and then click OK.
This dialog box is displayed using a method called prompt() which takes two parameters
(i) A label which you want to display in the text box (ii) A default string to display in the text
box.
This dialog box with two buttons: OK and Cancel. If the user clicks on OK button the window
method prompt() will return entered value from the text box. If the user clicks on the Cancel
button the window method prompt() returns null.
You can use prompt dialog box as follows:
<head>
<script type=”text/javascript”>
<!—
var retVal = prompt(“Enter your name : “, “your name here”);
alert(“You have entered : “ + retVal );
//—>
</script>
</head>
Self Assessment
Fill in the blanks:
14. An ........................... dialog box is mostly used to give a warning message to the users.
15. The ........................... dialog box is very useful when you want to pop-up a text box to get
user input.
LOVELY PROFESSIONAL UNIVERSITY 107