Ken Ward's JavaScript Tutorial 2

Ken Ward's New Java Script Tutorial

User input from a text box

This page shows how to get user input from a text box.

The following form has a text box. When you write your name in the text box, you get - well - see for  yourself. Enter your name and click the button.


If you entered your name in the box, then I hope you saw it in the alert. Here's the code in the HEAD of the document:

<script type="text/javascript">


function alert3()



alert('Your name is '+Namer);




Namer is variable that holds your name which you entered in the text box. The alert adds some text, 'Your name is ' in front of the name so you get the result in the alert that pops up. Note any text we want to write is put in single (') or double quotes (") (but not both!). Next we look at calling a function from text.

Next: Changing background colour

[If you need to learn more about HTML visit the HTML Tutorial]

I am always pleased to hear from you.
Send your comments to