In Association with Amazon.in   Flipkart

Friday, July 12, 2013

JavaScript Prompt Dialog Box Example

Prompt Dialog Box:- Prompt is used to take inputs at Runtime through dialog box.

Example-1:

<html>
<head>
         <script>
         
         a = prompt('please enter your value');
         document.write(a);

         </script>

</head>
<body>
</body>
</html>

Example-2:

<html>
<head>
         <script>
         
         a = prompt('please enter your value',100);
         document.write(a);

         </script>

</head>

<body>
</body>
</html>



Example-3:

<html>
<head>
         <script>
         
         a = prompt('please enter your value');
         document.write(a+'<br>'); 
         
         b = typeof(a);
         document.write(b);
         </script>

</head>

<body>
</body>
</html>

Example-4:

<html>
<head>
         <script>
         
         a = prompt('please enter your value');
         a = parseInt(a);
         
         b = typeof(a);
         document.write(a+'<br>'); 
         document.write(b);
         </script>

</head>

<body>
</body>
</html>

Example-5:

<html>
<head>
         <script>
         
         a = prompt('please enter 1st value');
         a = parseInt(a);
         
         b = prompt('please enter 2nd value');
         b = parseInt(b);

         c = a+b;
         document.write(c);
         </script>

</head>

<body>
</body>
</html>



Example-6:

<html>
<head>
         <script>
         
         a = 'abc';
         a = parseInt(a);
         
         document.write(a);

         </script>

</head>

<body>
</body>
</html>

Note : 

  if parseInt conversion is not possible then it will return NaN ( Not a Number )

No comments:

Post a Comment


Related Posts Plugin for WordPress, Blogger...