Allow Users to enter data into Message Box(Javascript Prompt)
Posted: February 28th, 2008 | Author: Nischal Shetty | Filed under: JavaScript | Comments OffJavascript has a function named ‘prompt’ which displays a message box along with a text box in it which allows users to input data.
Here’s how you achieve it :
function testPrompt()
{
var enteredData = prompt(“Type something in the text box below”,”");
alert(“You entered “+enteredData);
}
prompt() takes two parameters. The first parameter is used to display the message above the text box whereas the second parameter fills up the textbox with the values you specify(leave it blank if you want the text box to be empty)
To get a quick glimpse of the promt box copy paste the code below into your browser address bar and press enter :
Note: you’ll have to manually replace the double quotes(with double quotes again) after you copy paste the code due to the formatting in this page
javascript:var s = prompt(“Type something in the text box below”,”");alert(s);











