In the example given below document.getElementById returns a reference to our HTML element myText. We store this reference into a variable 'myTextField', and then use the 'value' property, that all input elements use to grab the value.
<script type="text/javascript">
function checkValue(){
var myTextField = document.getElementById('myText');
if(myTextField.value != "")
alert("You entered: " + myTextField.value)
else
alert("Would you please enter your age?")
}
</script>
<input type='text' id='myText' />
<input type='button' onclick='checkValue()' value='check age' />
0 Comment(s)