Things You'll Need:
- Text editor
-
Step 1
Start a new web page and include the opening and closing script tags in the web page header. The web page can be authored in a text or web page editor such as Adobe's DreamWeaver. The code to do this is:
<head>
<script>
</script>
</head> -
Step 2
Define a JavaScript method called MsgBox, which will accept a text string as an input argument within the opening and closing script tags. Within the MsgBox method, invoke the JavaScript alert method using the text string that is passed to the method as the data to display. This method will be invoked when the user clicks a form entry box that will be defined in a later step. The code to do this is:
<script>
function MsgBox (textstring)
{
alert (textstring)
}
</script> -
Step 3
Create the HTML code to accept a text input from the user that will be passed to the JavaScript method MsgBox. When the user selects the submission button, the text will be displayed to the user in an alert box. The code for the form is:
<body>
<FORM>
<INPUT NAME="text1" TYPE=Text>
<INPUT NAME="submit" TYPE=Button VALUE="Show A Javascript Alert" onClick="MsgBox(form.text1.value)">
</FORM>
</body>
</html> -
Step 4
Save the webpage and view it in your web browser. The data input into the text field will display in a JavaScript alert when you click the submission button.











