Quackit Logo
FREE Hosting!
With every domain you register with ZappyHost you get FREE hosting.
Create free Flash websites

JavaScript Prompt

Print Version

The JavaScript prompt box prompts the user to input text. The 'prompt' box is created using JavaScript's built-in prompt() function. When the JavaScript prompt() function is triggered, a small box will pop up and display a message to the user (supplied by you), a text field (for the user's input), an "OK" button, and a "Cancel" button.

Creating/Triggering a JavaScript Prompt

As mentioned, you create a JavaScript prompt box by calling the built-in JavaScript prompt() function. The function accepts two parameters: Your message to the user (for example, "What is your favorite website?"), and the default response (eg, "Quackit.com").

JavaScript Prompt - Basic Example

You can place the JavaScript prompt() function straight into an HTML tag. Like this:

JavaScript Prompt - A More Useful Example

The above example works, but it doesn't really do much. We asked the user for their input but we didn't do anything with their input!

We could make this more useful by using the user's input to determine what we display to them. So, here's another (more useful) example, where we include the JavaScript prompt() function within another function. Here, we make our website more personal by displaying the user's name in our message to them:

Here's an example:

Enjoy this website?

  1. Add this page to your Favorites
  2. Link to this page (copy/paste into your own website or blog):
  3. Help support Quackit by making a donation

Oh, and thank you for supporting Quackit!

Need Website Content?
Get unique, quality digital content for your website.
  • 270+ Website Templates
  • 800+ Flash Templates
  • 25,000+ Images, Logos
  • 30,000+ e-Books
  • 15,000+ Scripts
  • 27,000+ Animated GIFs
  • 21,000+ Ringtones
  • ...and much more!
Get your content now!
$1.99 .info domain names!
© Copyright 2000 - 2010 Quackit.com