Input

Keyboard

One of the commands used in JavaScript for input is the prompt command. This command displays an input box that allows a user to enter data and then to click a button for OK or Cancel.

JavaScript Prompt

Use a suitable text editor to type the following code that shows the use of the prompt command. Save the program as input.html

Open the saved program in a web browser to check if it works properly. If the program is working you should be able to type in some text and then click on one of the buttons.

Note: make sure that you type the program in exactly because JavaScript is case sensitive.

<html>

<head>

<script type='text/javascript'>

var forename = prompt ('What is your name?');

alert ('Hello ' + forename);

</script>

</head>

<body>

</body>

</html>

Next: Process