|
JavaScript Home
JavaScript TutorialIntroductionHow to Enable JavaScript JavaScript Syntax JavaScript Popup Boxes JavaScript and HTML External JavaScript File JavaScript Operators JavaScript Variables JavaScript Functions JavaScript Events JavaScript If Statements JavaScript Switch Statements JavaScript While Loop JavaScript For Loop JavaScript Try Catch JavaScript Escape Characters JavaScript Void(0) JavaScript Cookies JavaScript Date and Time JavaScript Arrays Two Dimensional Arrays JavaScript innerHTML JavaScript Summary JavaScript ReferenceJavaScript Reserved WordsJavaScript Event Handlers JavaScript Date and Time Functions JavaScript ExamplesList of ExamplesJavaScript Dropdown Menu JavaScript Print JavaScript Alert Box JavaScript Confirm JavaScript Prompt JavaScript Status Bar Messages Image Rollovers Popup Windows JavaScript Redirect Timed JavaScript Redirect JavaScript Refresh Page |
JavaScript PromptThe JavaScript prompt box prompts the user to input text. The 'prompt' box is created using JavaScript's built-in Creating/Triggering a JavaScript PromptAs 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 ExampleYou can place the JavaScript prompt() function straight into an HTML tag. Like this: JavaScript Prompt - A More Useful ExampleThe 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: |
Need Website Content?
Get unique, quality digital content for your website.
|