SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Dec 2012
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    TypeError: document.getelementbyid(...) is null

    Code:
    <html>
    
    	<head>
    		<title>Port Scanner for Mozilla Firefox</title>
    	</head>
    	
    	<body>
    
    		<form name="my_form" id="my_form" method="post" action="#" onsubmit="return displayMessage();">
    			<p align="center">URL/Domain Name/IP Address: <input type="text" size="20" name="uri" value="" placeholder="http://www.google.com" required/></p>
    			<table align="center" border="1" width=100% bgcolor="#f4fff0" bordercolor="green" cellspacing="2" cellpadding="2">
    				<tr>
    					<td align="center">
    						Start port: <input type="text" size="5" name="start_port" maxlength="5">
    						End port: <input type="text" size="5" name="end_port" maxlength="5"><br>
    						<input type="submit" value="Scan all ports" name="scan_all"><br>
    						<input type="submit" value="Scan only open ports" name="scan_open">						
    					</td>
    				
    				</tr>
    				<tr>
    					<td align="center">
    						<input type="text" size="20" name="scan_tcp"><br>
    						<font color="#b1b1b1">Enter port numbers separated by space. (e.g. 21 25 80)</font><br>
    						<input type="submit" value="Scan TCP ports" name="scan_tcp_ports">					
    					</td>
    				</tr>
    				<tr>
    					<td align="center">
    						<input type="submit" value="Scan common service ports" name="scan_common_tcp"><br>
    						<input type="submit" value="Scan common Trojan ports" name="scan_common_trojan_tcp">					
    					</td>
    				</tr>
    			</table>
    		</form>
    	    <script type="text/javascript">
    			function displayMessage()
    			{
    					if(document.my_form.uri.value==0)
    					{
    						document.write("<font color='red'><i>Please enter URL/Domain Name/IP Address.</i></font>");
    						return false;
    					}
    					document.write("<DIV id='loading'><BR><BR><font color='#FF6600'><i>Please wait... The ports are being scanned...</i></font></DIV>");
    					document.getElementById("my_form").submit();					
    			}
    		    window.onload=function()
    			{  
    				document.getElementById("loading").style.display="none";  
    		    }  
    		</script>
    	</body>
    </html>
    I want to submit above form. But it shows me JavaScript error in Console that
    "TypeError: document.getelementbyid(...) is null"
    This error is for code :
    document.getElementById("my_form").submit();

    I am using Firefox 24.0 and Windows 7. I have installed only 1 add-on. That is 'Firebug 1.12.3'.
    This code works fine for other browsers Except Firefox.
    Please help me to solve this problem.
    Last edited by Pullo; Oct 13, 2013 at 03:33. Reason: Added code tags

  2. #2
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    6,060
    Mentioned
    219 Post(s)
    Tagged
    12 Thread(s)
    This is because document.write will overwrite the entire DOM if it's called after the document has finished being parsed.

    Once I have submitted the form, see the "loading" message, then inspect the DOM using FireBug, I see:

    Code:
    <html>
      <head></head>
      <body>
        <div id="loading">
          <br><br><font color="#FF6600"><i>Please wait... The ports are being scanned...</i></font>
        </div>
      </body>
     </html>
    hence why document.getElementById("my_form") is null.

    It would be better to create a <div> element, set the text accordingly, then append it to your form.

    HTH

  3. #3
    SitePoint Member
    Join Date
    Dec 2012
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you very much for help.
    I could solve this error by using 'innerHTML'.


    Quote Originally Posted by Pullo View Post
    This is because document.write will overwrite the entire DOM if it's called after the document has finished being parsed.

    Once I have submitted the form, see the "loading" message, then inspect the DOM using FireBug, I see:

    Code:
    <html>
      <head></head>
      <body>
        <div id="loading">
          <br><br><font color="#FF6600"><i>Please wait... The ports are being scanned...</i></font>
        </div>
      </body>
     </html>
    hence why document.getElementById("my_form") is null.

    It would be better to create a <div> element, set the text accordingly, then append it to your form.

    HTH


Tags for this Thread

Bookmarks

Posting Permissions

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