...

View Full Version : got error: Invalid argument



san_crazy
03-20-2009, 05:42 PM
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



<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

randomuser773
03-20-2009, 08:55 PM
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:
function Del_sub_menu()
{
var srcHolder = document.getElementById("sub_menus");

while(srcHolder.childNodes.length)
srcHolder.removeChild(srcHolder.firstChild);
}

san_crazy
03-21-2009, 05:33 AM
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?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum