Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to use getElementById() method in javascript

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 223
    Comment on it

    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.

    1. <script type="text/javascript">
    2. function checkValue(){
    3. var myTextField = document.getElementById('myText');
    4. if(myTextField.value != "")
    5. alert("You entered: " + myTextField.value)
    6. else
    7. alert("Would you please enter your age?")
    8. }
    9. </script>
    10. <input type='text' id='myText' />
    11. <input type='button' onclick='checkValue()' value='check age' />

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: