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 3 of 3
  1. #1
    Regular Coder
    Join Date
    Sep 2008
    Posts
    116
    Thanks
    2
    Thanked 0 Times in 0 Posts

    got error: Invalid argument

    I am trying to design menu and also been successful at some extent.
    Root menu items doesn't create any problem but when I used following code to create drop down submenu items i got the error:Invalid argument
    The error causing line is bold

    Code:
    <html>
       <head>
       <script language="javascript">		
    
    		function Create_sub_menu(rowCount, leftPos)
    		{
    		    var srcHolder =  document.getElementById("sub_menus");
    			if(IsValidNumber(rowCount) && (srcHolder != null) && (srcHolder.canHaveChildren))
    			{
    				srcHolder.innerHTML = "";
    				var srcTable =  document.createElement("table");				
    				srcTable.style.border = "solid";	
    				srcTable.style.borderWidth = "1px";			
    				srcTable.style.borderColor = "Black";
    				srcTable.style.height = 20*rowCount;
    				srcTable.style.width = "100%";
    				srcHolder.style.width = "150px";
    				srcHolder.style.height = 20*rowCount;
    				srcHolder.style.position = "absolute";
    				srcHolder.style.marginLeft = leftPos;			
    				var tmpRow = null;
    				var tmpCell = null;
    				srcHolder.appendChild(srcTable);
    				for(i=0; i<rowCount; i++)
    				{
    					tmpRow = AppendRow(srcTable)
    					for(j=0; j<1; j++)
    					{
    						tmpCell = AppendCell(tmpRow);
    						tmpCell.innerText = j;
    						tmpCell = null;
    					}
    					tmpRow = null;
    				}
    			}
    		}
    
    		function AppendRow(srcTable)
    		{
    			if(srcTable != null)
    			{
    				return srcTable.insertRow();
    			}
    			else
    			{
    				alert("Error while creating table. Cause: Container Table is null!");
    			}
    		}
    
    		function AppendCell(srcRow)
    		{
    			if(srcRow != null)
    			{
    				return srcRow.insertCell();
    			}
    			else
    			{
    				alert("Error while creating table. Cause: Container row is null!");
    			}
    		}
    
    		function IsValidNumber(ipNum)
    		{
    			if(isNaN(ipNum))
    			{
    				alert("Invalid Number!");
    				return false;
    			}
    			else if(ipNum < 1)
    			{
    				alert("Number should be greater than 0!");
    				return false;
    			}
    			else
    			{
    			return true;
    			}
    		}
    		
    	   function Del_sub_menu()
    	     {
    		    var srcHolder =  document.getElementById("sub_menus");			 
    			var parent_node =  document.getElementById("main_body");
    			parent_node.removeChild(srcHolder);
    			
    		 }	
    	</script>
    
      </head>
      <body>
         <div id="outer_pane">
    	    <div id="header">
    		  <img src="http://localhost/gargi_collg/external/images/collg_name.png" style="position:absolute; margin-left:20px; margin-top:30px;" />		  
    		</div>
    	    <div class="top_x_menu">       
              <table cellpadding="0" cellspacing="0">
    		    <tr>
    			 <td>
    			   <a class="tx_menu_item" href="#">Home</a>
    			 </td>
    			 <td>
    			    <a class="tx_menu_item" href="#" onMouseOver="Create_sub_menu(7,139)" onMouseOut="Del_sub_menu()">About Us</a>
    			 </td>
    			 <td>
    			   <a class="tx_menu_item">Career</a>
    			 </td>
    			 <td>
    			   <a class="tx_menu_item">Courses</a>
    			 </td>
    			 <td>
    			    <a class="tx_menu_item">Faculties</a>
    			 </td>
    			 <td>
    			   <a class="tx_menu_item">College</a>
    			 </td>
    			 <td>
    			    <a class="tx_menu_item">Get In</a>
    			 </td>
    			 <td style="border:none;" >
    			    <a class="tx_menu_item">Contact Us</a>
    			 </td>
    			</tr>
    		  </table>
    		</div>
    		<div id="main_body">
    		  <div class="left_menu">
    		   <div class="leftu_pane">
    		    
    		   </div>		
    		   <div class="leftm_pane">		   
    		   </div> 
    		   <div class="leftb_pane">
    		     fgfdg
    		   </div>
    		  </div>
    		  <div class="info_area">
    		   <div class="infou_pane">
    		   </div>
    		   <div class="infom_pane">			   
    		   </div>		
    		   <div class="infob_pane">
    		   </div>
    		  </div> 
    		  <div id="sub_menus">
    		  </div>
    		</div>
    	 </div>
      </body>
    </html>
    While this javascript code doesn't work in FF3.x.x but in IE.
    I cant nail out the problem, hope you must

    thanks
    Last edited by san_crazy; 03-20-2009 at 06:44 PM.

  • #2
    Banned
    Join Date
    Nov 2008
    Location
    not found
    Posts
    284
    Thanks
    0
    Thanked 53 Times in 51 Posts
    Quote Originally Posted by san_crazy View Post
    Code:
    	   function Del_sub_menu()
    	     {
    		    var srcHolder =  document.getElementById("sub_menus");			 
    			var parent_node =  document.getElementById("main_body");
    			parent_node.removeChild(srcHolder);
    			
    		 }
    You're removing a div and then still expecting it to be there next time. Just remove its children:
    Code:
    function Del_sub_menu()
    {
      var srcHolder =  document.getElementById("sub_menus");			 
    						
      while(srcHolder.childNodes.length) 
       srcHolder.removeChild(srcHolder.firstChild);
    }

  • #3
    Regular Coder
    Join Date
    Sep 2008
    Posts
    116
    Thanks
    2
    Thanked 0 Times in 0 Posts
    yess!!! its done

    but there is still one more problem, I have edited the code and fixed all the errors, but it doesn't work in FF3.x.x
    its not a problem with IE7.0

    any suggestion?


  •  

    Posting Permissions

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