Getting input from the user

We can use JavaScript's alert command to display information to the user but we also need to be able to read the user's input. We can use the prompt command to do this.

Type this html page into NotePad++:

<html>
  <!-- Getting input from the user -->
  <head>
    <title>My second program</title>
  </head>
  <body>
    <script>
      userName = prompt("What is your name", "")
      alert("Hello " + userName + ".")
    </script>
    This text will appear after you close the alert.
  </body>
</html>

Save the file and open it in FireFox.

You should see a box on screen asking for your name. [Getting user input with the prompt() command.]

Enter your name and you should see a welcome message. [Displaying a message with the alert() command.]

This program introduces the concepts of variables , strings and parameters in JavaScript.

MS Access technical tips

Visual FoxPro technical tips

General Tips

 

More tips from Alvechurch Data

Search page for Alvechurch Data

Searching a web site with JavaScript

Read More

Site Map

Site map of the Alvechurch Data site

Read More

Javascript while loops

JavaScript do and while loops

Read More

Javascript for loops

Javascript for loops

Read More

Repetition in Javascript

JavaScript structures for repetition

Read More