Try this and use your BACK button to return to this article.
The Confirm dialog box is an excellent way to give visitors more control and let them have a second chance to consider their options.
A "prompt box" asks the user for some small bit of information that's necessary to complete the task. Common uses include:
Prompt boxes are extremely useful and versatile tools, but use them with care. The user should only be asked to enter a short word or numeric answer to a simple question. Don't ask questions that might get a multiple sentence or multiple line response.
As with the Confirm box, you can write some extremely simple code - but it's not too useful. Try this and use your BACK button to return to this article.
<a href='javascript:onClick=window.prompt("How many pet turtles do you have? Please enter a number from 1 to 25", "1")'>Test the Prompt box.</a>
Note that window.prompt has two parts:
prompt("message to be displayed","default value")
You don't have to enter a default value, but if you leave it blank, JavaScript will display the value "undefined" in the prompt box.
Now let's create a prompt box that passes the value to a variable and inserts it into page text.
Place this code in the HEAD section of your document.
<script language="javascript" type="text/javascript">
var yourName = prompt("Please enter your first name.", "Your Name Goes Here");
</script>
Then, include the variable called "yourName" inside the text wherever you want it using a document.write statement:
Hello <script language="javascript">document.write(yourName)</script>! It's so nice to have you back.
By the way, <script language="javascript">document.write(yourName)</script>, we have several sale items you may be interested in….
Here's how it looks on this example page
Note that the page opens a JavaScript pop-up window. You may have to instruct your pop-up blocker to accept it if you don't see the window when you click the link. For more information about creating JavaScript pop-ups, see our April, 2001 JavaScript Tip: Put Your Window Where You Want It.