Easy tech stuff!

Allow Users to enter data into Message Box(Javascript Prompt)

Posted: February 28th, 2008 | Author: Nischal Shetty | Filed under: JavaScript | Comments Off

Javascript 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);

http://www.techtamasha.com/wp-content/plugins/sociofluid/images/digg_48.png http://www.techtamasha.com/wp-content/plugins/sociofluid/images/reddit_48.png http://www.techtamasha.com/wp-content/plugins/sociofluid/images/stumbleupon_48.png http://www.techtamasha.com/wp-content/plugins/sociofluid/images/delicious_48.png http://www.techtamasha.com/wp-content/plugins/sociofluid/images/furl_48.png http://www.techtamasha.com/wp-content/plugins/sociofluid/images/technorati_48.png http://www.techtamasha.com/wp-content/plugins/sociofluid/images/google_48.png http://www.techtamasha.com/wp-content/plugins/sociofluid/images/myspace_48.png http://www.techtamasha.com/wp-content/plugins/sociofluid/images/facebook_48.png http://www.techtamasha.com/wp-content/plugins/sociofluid/images/yahoobuzz_48.png http://www.techtamasha.com/wp-content/plugins/sociofluid/images/twitter_48.png

Comments are closed.