JavaScript Prompt Box : Accepting Value from User

January 30, 2025 No Comments » Hits : 472





JavaScript Prompt Box : Accepting Data Value from User using Prompt box

Prompt Box

  • Prompt() is a method of the window object.
  • It is similar with alert box except for one addition.
  • Prompt Box have “Cancle Button” on the pop up window.
  • Prompt Box have “textbox” , which allows user to enter value.

Sample Example

<html>
<head>
<script type="text/javascript">
function show_prompt()
{
var name=prompt("Please enter your name","Pritesh");
if(name!=null && name!="")
  {
  document.write("<p>Hello " + name + "</p>");
  }
}
</script>
</head>
<body>
<input type="button"
       onclick="show_prompt()"
       value="Show prompt box"/>
</body>
</html>

Output :

  1. Script will get input from textbox.
  2. If user clicks “OK” then input will be accepted and accepted input gets processed.
  3. If user clicks “Cancle” then input will be rejected and popup winodow will be closed.

Output :

JavaScript Prompt Box

Download Prompt Box Example : Click Here

Incoming search terms: