08 Dec 2013
Popups in javascript
There are three kinds of popup boxes in JavaScript
Who to define array in php?
- Alert box
- Confirm box
- Prompt box
Alert box display message with ok button
Example:
<html>
<script>
alert(“Hello Viewers”);
</script>
</html>
<script>
alert(“Hello Viewers”);
</script>
</html>
Confirm box display message with ok and cancel button, it is use to take user confirmation. If we click ok, it returns TRUE and if we click cancel it returns FALSE.
Example:
<html>
<script>
var a = confirm(“Are you sure!”);
if(a)
{
// true statement
}
else
{
// false statement
}
</script>
</html>
<script>
var a = confirm(“Are you sure!”);
if(a)
{
// true statement
}
else
{
// false statement
}
</script>
</html>
Prompt box is use to take input from user. Prompt box returns the string value and if required we can convert string value to integer with help of parseInt() method.
Example:
<html>
<script>
var a = prompt(“Enter Name “);
alert(“Hello “+a);
var age = parseInt(prompt(“Enter Age “));
alert(“You are “+ age +” years Old”);
</script>
</html>
<script>
var a = prompt(“Enter Name “);
alert(“Hello “+a);
var age = parseInt(prompt(“Enter Age “));
alert(“You are “+ age +” years Old”);
</script>
</html>