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
    • 160
    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.

    <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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: