please dont rip this site

JavaScript: The Definitive Guide

Previous Chapter 21
JavaScript Reference
Next
 

Window.prompt() Method

Name

Window.prompt() Method---get string input in a dialog

Availability

Navigator 2.0, Internet Explorer 3.0

Synopsis

window.prompt(message)
window.prompt(message, default)

Arguments

message

The plain text (not HTML) string to be displayed in the dialog. It should ask the user to enter the information you want. On Windows platforms, only one line messages are allowed.

default

An optionally specified string or integer which will be displayed as the default input in the dialog. If null is specified, or if this argument is not passed at all, then prompt() displays the string "<undefined>" as the default value. Pass the empty string ("") to make prompt() display an empty input box.

Returns

The string entered by the user, or the empty string if the user did not enter a string, or null if the user clicked Cancel.

Description

The prompt() method displays the specified message in a dialog box that also contains a textual input field and OK, Clear, and Cancel buttons. Platform-dependent graphics in the dialog help to indicate to the user that her input is desired.

The default argument specifies the text that initially appears in the input field. If default is null, or if this optional argument is not passed at all, then the initial text is "<undefined>". If default is the empty string ("") then the input field is initially empty. Otherwise, the input field displays the string or number that is passed as the default.

If the user clicks the Cancel button, prompt() returns null. If the user clicks the Clear button, prompt() erases any current text in the input field. If the user clicks the OK button, prompt() returns the value current value displayed in the input field. Note, however, that if the input field is displaying "<undefined>" because the default argument was null or unspecified, then prompt() returns the empty string and not the string "<undefined>". Also note that prompt() always returns the user's input as a string value, even if default was specified as a numeric value. If necessary, you can use parseInt() or parseFloat() to convert the returned string to a number.

The dialog box that is displayed by the prompt() method is modal--that is, it blocks all user input to the main browser window until the user dismisses the dialog by clicking on the OK or Cancel buttons. Since this method returns a value depending on the user's response to the dialog, JavaScript execution pauses in the call to prompt(), and subsequent statements are not executed until the user responds to the dialog.

Usage

Note that the question displayed in the dialog is a string of plain text, not of formatted HTML. Unlike the message displayed by the alert() and confirm() methods, the message displayed by prompt() may only be a single line long on Windows platforms.

See Also

"Window", "Window.alert()", "Window.confirm()"


Previous Home Next
Window.parent Book Index Window.scroll()

HTML: The Definitive Guide CGI Programming JavaScript: The Definitive Guide Programming Perl WebMaster in a Nutshell

file: /Techref/language/java/SCRIPT/definitive/refp_457.htm, 7KB, , updated: 2019/10/14 15:00, local time: 2024/11/25 19:53,
TOP NEW HELP FIND: 
18.116.43.109:LOG IN

 ©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE!

<A HREF="http://techref.massmind.org/techref/language/java/SCRIPT/definitive/refp_457.htm"> [Chapter 21] Reference: Window.prompt()</A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type a nice message (short messages are blocked as spam) in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.


Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?

 

Welcome to massmind.org!

 

Welcome to techref.massmind.org!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .