Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Oct 2009
    Posts
    434
    Thanks
    7
    Thanked 3 Times in 3 Posts

    how do i check if document.getElementById('email2') exists before getting its value

    is there a way to do this with javascript ?

    Code:
    var fID = document.getElementById('email2');

  • #2
    Senior Coder coothead's Avatar
    Join Date
    Jan 2004
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    1,699
    Thanks
    0
    Thanked 233 Times in 228 Posts
    Hi there needsomehelp,

    does this help...
    Code:
    
    <script type="text/javascript">
    
    function init(){
    
       var fID=document.getElementById('email2');
    
    if(fID){
       /* replace this alert with appropriate code */
       alert('fID exists');
     }
    else {
       alert('fID does not exist');
       return;
      }
     }
       window.addEventListener?
       window.addEventListener('load',init,false):
       window.attachEvent('onload',init);
    
    </script>
    
    coothead


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •