#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    5
    Rep Power
    0

    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=""  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.
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Please use [ CODE ] tags and preview your post before you submit it. Your code is completely unformatted and more or less unreadable.



    Originally Posted by AbhijeetM
    This code works fine for other browsers Except Firefox.
    No, the code doesn't work in any browser. You try to access #loading right after the page has loaded, but the element doesn't even exist at that point of time. It only gets created after submitting the form.

    Apart from that, you're using a lot of bad and obsolete stuff like the font element or the bgcolor attribute. And document.write() is bad practice. Whatever tutorial or teacher you got this from: You definitely need a better source. This stuff is from the late 90s. I recommend you check out the tutorials of the Mozilla Developer Network to learn modern HTML and JavaScript.

    And I hope you're not doing anything fishy with that port scanner?
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    5
    Rep Power
    0

    Thank you


    Thank you very much for help.
    I could solve this error by using 'innerHTML'.
  6. #4
  7. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Originally Posted by AbhijeetM
    I could solve this error by using 'innerHTML'.
    That sounds a lot better.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    22
    Rep Power
    0
    First, the answer to your question: in your "displayMessage" function, you need to just return true instead of re-calling the form submit. this creates a circular pointer.

    I put your updated code in jsfiddler for you

    http://jsfiddle.net/4xQHP/

    Second, using innerHTML is not any better then document.write. People still use it and most of current browsers still support it however innerHTML is already marked to be deprecated in future HTML.

    The correct way to do it is, more cumbersome code, using document.createElement. Using the following link for more info.
    http://stackoverflow.com/questions/7...-for-innerhtml

    But if you choose connivence of efficiency, I suggest to use jQuery (or any of your favorite, well-known, javascript library)
    Most of library have alternative of innerHTML function.

    FYI, in jQuery it is
    Code:
    //document.write("<font color='red'><i>Please enter URL/Domain Name/IP Address.</i></font>");
    
    $("body").html("<font color='red'><i>Please enter URL/Domain Name/IP Address.</i></font>");
  10. #6
  11. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Are you just trolling, jkdev?



    Originally Posted by jkdev
    Second, using innerHTML is not any better then document.write. People still use it and most of current browsers still support it however innerHTML is already marked to be deprecated in future HTML.
    What? It's the exact opposite: innerHTML is about to become standardized in HTML5 (which it currently isn't). And that's actually great, because innerHTML() is very fast.

    So what do you know about innerHTML() that the W3C obviously doesn't know?



    Originally Posted by jkdev
    But if you choose connivence of efficiency, I suggest to use jQuery (or any of your favorite, well-known, javascript library)
    Most of library have alternative of innerHTML function.
    And what does jQuery use under the hood? innerHTML().
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    22
    Rep Power
    0
    Originally Posted by Jacques1
    What? It's the exact opposite: innerHTML is about to become standardized in HTML5 (which it currently isn't). And that's actually great, because innerHTML() is very fast.

    So what do you know about innerHTML() that the W3C obviously doesn't know?
    HTML5 is finalized LAST YEAR.
    http://www.w3.org/News/2012#entry-9667
    http://developers.slashdot.org/story/12/12/17/2019230/

    FYI, it is 2013 now.

IMN logo majestic logo threadwatch logo seochat tools logo