asp多级联动菜单,多级联动菜单
<!--#include file="adoconn.asp"-->
<script>
var m_oXMLDoc = new ActiveXObject("Microsoft.XMLDOM");
var m_sBaseSrc = "Tree.asp?ParentCode=";
function BindSelect( strXMLSrc , objSelectName, defaultVal)
{
m_oXMLDoc.async = true;
m_oXMLDoc.onreadystatechange = Function( "fnLoadComplete('" + objSelectName + "', '" + defaultVal + "');" );
m_oXMLDoc.load( strXMLSrc );
}
function fnLoadComplete(objSelectName, defaultVal)
{
var objSelect = document.all[objSelectName];
var aryXMLNodes;
var node;
if (objSelect == null)
return;
try
{
var iReadyState = m_oXMLDoc.readyState;
}
catch(e)
{
return;
}
if( iReadyState != 4 ) return;
if( m_oXMLDoc != null && m_oXMLDoc.xml != "" )
{
objSelect.length = 0;
aryXMLNodes = m_oXMLDoc.documentElement.selectNodes("TreeNode");
objSelect.options[0] = new Option("==全部==");
for (var i=0; i < aryXMLNodes.length; i++)
{
node = aryXMLNodes[i];
objSelect.options[i+1] = new Option(node.getAttribute("Title"),node.getAttribute("MaterialClassCode"));
}
if (defaultVal != null && defaultVal != "" && objSelect.length > 1)
{
SetSelectedValue(objSelect, defaultVal)
}
if(objSelect.ChildSelectName != null)
{
objSelect.onchange = Function( "var val = this.options[this.selectedIndex].value;BindSelect(m_sBaseSrc+val, '"+objSelect.ChildSelectName+"', '"+defaultVal+"');if(val!='')document.all.MaterialClassCode.value=val;" );
objSelect.fireEvent("onchange");
}
else
{
objSelect.onchange = Function( "var val = this.options[this.selectedIndex].value;if(val!='')document.all.MaterialClassCode.value=val;" );
}
}
}
function InitSelect(defaultVal)
{
document.all.MaterialClassCode.value = "";
BindSelect( m_sBaseSrc + "00", "MaterialClass1", defaultVal);
}
function Equality(val1,val2)
{
if (val1.length < val2.length || val2 == "")
return false;
return (val1.substr(0,val2.length) == val2)
}
function SetSelectedValue(oSel,val)
{
if (val == null)
return;
for(var i=0; i<oSel.length; i++)
{
if (Equality(val, oSel.options[i].value))
{
oSel.selectedIndex = i;
if(oSel.ChildSelectName == null)
oSel.fireEvent("onchange");
break;
}
}
}
window.onload = function(){InitSelect();}
</script>
<nobr>
<select name="MaterialClass1" ChildSelectName="MaterialClass2"></select>
<select name="MaterialClass2" ChildSelectName="MaterialClass3"></select>
<select name="MaterialClass3" ChildSelectName="MaterialClass4"></select>
<select name="MaterialClass4"></select>
</nobr>
<input type="hidden" name="MaterialClassCode">