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