Monday 15 January 2018

Popup Boxes In JavaScript

Popup Boxes
There are three types of popup boxes: Alert box, Confirm box, and Prompt box
Alert Box
It display the message in small window that pops up on your screen
alert box is called as message box
Syntax
alert("statement");

Example

<!doctype html>
<html>
<body>

<h2> Alert Box Example</h2>

<button onclick="display()">Click</button>

<script>

function display()
 {
   alert("Welcome to LearningPoint92");
}
</script>
</body>
</html>

Confirm Box
A confirm box is used when the user will  click either "OK" or "Cancel"  button to proceed.
Syntax
confirm("Statement");
Example
<!doctype html>
<html>
<head> Confirm Box Example</head></br>
<body>
<button onclick="display()">Click</button>
<script>
function display() {
 if (confirm("Click on the button(Ok or Cancel)") == true)
     {
        alert("Welcome to LearningPoint92");
     }
   else
     {
        alert("You are in wrong place");
      }
   }
</script>
 </body>
</html>
  OR
<!doctype html>
<html>
<head>Confirm Box Example</head></br>
<body>
<button onclick="display()">Click</button>
 <p id="dmscript"></p>
<script>
function display() {
    var str;
if (confirm("Click on the button(Ok or Cancel)") == true)
       {
        str="Welcome to LearningPoint92";
       }
       else
       {
        str = "You are in wrong place";
        }
    document.getElementById("dmscript").innerHTML =str;
                        }
 </script>
 </body>
</html>
Prompt Box
It is used to taking value from user.
Syntax
prompt("Message");

Example

<!doctype html>
<html>
<head>Prompt Box Example</head>
</br>
<body>
<script>
var name =prompt("Enter Name");

var age =parseInt(prompt("Enter Age"));

var mark=parseFloat(prompt("Enter mark"));

alert("StudentDetails\n"+"Name::"+name+"\nAge::"+age+"\nMarks::"+mark);

</script>
</body>
</html>


No comments:

Post a Comment

apply function in R

1) apply function: It takes 3 arguments matrix,margin and function.. Example: m<-matrix(c(1,2,3,4),nrow=2,ncol=2) m #1 indicates it is ap...