Thursday, 23 August 2018

Javascript: prompt box

‘prompt’ box is used to read input from user.

Syntax
input = prompt(text[, default]);

As you see the syntax, prompt box takes two arguments; text is the message to be displayed on the prompt box. If user types nothing and press OK then input is assigned with default value, If user press Cancel button then input is null, else assigned with the value entered by user.

prompt.html
<!DOCTYPE html>

<html>
 <head>
  <title>prompt box</title>
 </head>
 
 <body>
  <script type="text/javascript">
   var data = prompt("Enter any thing and press OK", "Good Morning");
   
   document.write("You Entered " + data);
  </script>
 </body>
</html>



Previous                                                 Next                                                 Home

No comments:

Post a Comment