First you need to get a DOM (Document Object Model) link to the text box:
<input type="text" id="mytextbox" value="Hello World!" />
Pay attention to the id attribute, the text field now has the identifier mytextbox .
The next step is to get the link in JavaScript:
var textbox = document.getElementById('mytextbox');
This will retrieve the HTML element using the id attribute. Please note that these identifiers must be unique, therefore you cannot have two text fields with the same identifier.
Now the last step is to get the value of the text field:
alert(textbox.value);
The value property contains the contents of the text field and what is it!
For more information, you can check out some things in MDC:
GetElementByID Help
Input Element Link
DOM Overview
Ivo Wetzel
source share