document.getElementById() is null or...

Discussion in 'JavaScript' started by jonhyhar, Dec 16, 2010.

  1. #1
    hello guys, I get an error like "document.getElementById() is null or not an object" for this code, can somebody help me?


    
    <script type="text/javascript">
    <!--
    document.getElementById('aramayeri').onsubmit = function() {
        var hash =  '%2F' + encodeURI(document.getElementById('queryds').value) + '?ara=' + encodeURI(document.getElementById('aramaici').value) + '&go';
        window.location.hash = hash;
        return false;
    }
    //-->
    </script>
    
            <form id="aramayeri" class="global_search_form" action="ara.php" method="GET">
    		  <input id="queryds" type="hidden" value="ara.php" />
              <input id="aramaici" type="text" class="text suggested aaad" name="ara" size="20" maxlength="100" value="" alt="Search" />
              <input type="submit" class="ara_ok" value="">
    
            </form>
    
    Code (markup):

     
    Last edited: Dec 16, 2010
    jonhyhar, Dec 16, 2010 IP
  2. tvoodoo

    tvoodoo Active Member

    Messages:
    239
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    53
    #2
    
    <script type="text/javascript">
    <!--
    var form = document.getElementById('aramayeri');
    form.onsubmit = function() {
        var hash =  '%2F' + encodeURI(document.getElementById('queryds').value) + '?ara=' + encodeURI(document.getElementById('aramaici').value) + '&go';
        window.location.hash = hash;
        return false;
    }
    //-->
    </script>
    
    HTML:
    OR

    
    <script type="text/javascript">
    <!--
    function test_form() {
        var hash =  '%2F' + encodeURI(document.getElementById('queryds').value) + '?ara=' + encodeURI(document.getElementById('aramaici').value) + '&go';
        window.location.hash = hash;
        return false;
    }
    //-->
    </script>
    
    <form id="aramayeri" class="global_search_form" action="ara.php" method="GET" onsubmit='test_form()'>
    		  <input id="queryds" type="hidden" value="ara.php" />
              <input id="aramaici" type="text" class="text suggested aaad" name="ara" size="20" maxlength="100" value="" alt="Search" />
              <input type="submit" class="ara_ok" value="">
    
            </form>
    
    HTML:
     
    tvoodoo, Dec 16, 2010 IP
  3. jonhyhar

    jonhyhar Active Member

    Messages:
    166
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #3
    thank for your reply tvoodoo but I still get the same error =/
     
    jonhyhar, Dec 16, 2010 IP
  4. tvoodoo

    tvoodoo Active Member

    Messages:
    239
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    53
    #4
    for version one ? did you try the second one ?
     
    tvoodoo, Dec 16, 2010 IP
  5. jonhyhar

    jonhyhar Active Member

    Messages:
    166
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #5
    I tried the first one (gives the same error)
    the second one doesn't give an error but it doesn't work ( i mean it doesn't change the hash in url )
     
    jonhyhar, Dec 17, 2010 IP
  6. tvoodoo

    tvoodoo Active Member

    Messages:
    239
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    53
    #6
    This works fine for me... so it's not from the html , check the php file.
    
    <script type="text/javascript">
        <!--
        function test_form() {
            var hash =  '%2F' + encodeURI(document.getElementById('queryds').value) + '?ara=' + encodeURI(document.getElementById('aramaici').value) + '&go';
            window.location.hash = hash;
            return false;
        }
        //-->
        </script>
    
    <form id="aramayeri" class="global_search_form" action="ara.php" method="GET" onsubmit='return test_form();'>
        <input id="queryds" type="hidden" value="ara.php" />
        <input id="aramaici" type="text" class="text suggested aaad" name="ara" size="20" maxlength="100" value="" alt="Search" />
        <input type="submit" class="ara_ok" value="" />
    </form>
    
    HTML:
     
    tvoodoo, Dec 17, 2010 IP
  7. jonhyhar

    jonhyhar Active Member

    Messages:
    166
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #7
    this works very well, thank you very...very much, I love you man!! :D
     
    jonhyhar, Dec 17, 2010 IP
  8. tvoodoo

    tvoodoo Active Member

    Messages:
    239
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    53
    #8
    Haha , your welcome ! :)
     
    tvoodoo, Dec 17, 2010 IP