81,095
社区成员
发帖
与我相关
我的任务
分享
<select name= "bigTypeSelect " onchange= "getSmallType(this.value); ">
<option value= "-1 ">
未选择
</option>
<c:forEach items= "${bigTypeList} " var= "temp ">
<option value= "${temp.typeId} ">
${temp.typeName}
</option>
</c:forEach>
</select>
<br/>
<select name= "typeId ">
<option value= "-1 ">
未选择
</option>
</select>
<script type= "text/javascript ">
//创建XMLHttpRequest对象
function createXMLHttpRequest()
{
//Mozilla 浏览器
if(window.XMLHttpRequest)
{
XMLHttpReq = new XMLHttpRequest();
}
// IE浏览器
else if (window.ActiveXObject)
{
try
{
XMLHttpReq = new ActiveXObject( "Msxml2.XMLHTTP ");
}
catch (e)
{
try
{
XMLHttpReq = new ActiveXObject( "Microsoft.XMLHTTP ");
}
catch (e) {}
}
}
}
//发送请求函数
function getSmallType(bigTypeId)
{
if(bigTypeId == -1)
{
var typeId = document.forms[0].typeId;
//清空select所有option选项
typeId.options.length = 0;
var option = document.createElement( "option ");
option.text = "未选择 ";
option.value = -1;
typeId.options.add(option);
return false;
}
createXMLHttpRequest();
XMLHttpReq.onreadystatechange = getFinsh;
var url = "getsmalltype.do?bigtypeid= "+bigTypeId;
XMLHttpReq.open( "post ",url , true);
XMLHttpReq.send(null);
}
//处理返回响应函数
function getFinsh()
{
if (XMLHttpReq.readyState == 4)
{
if (XMLHttpReq.status == 200)
{
if(window.ActiveXObject)
{
var xmlDom = new ActiveXObject( "Microsoft.XMLDOM ");
}
else
{
if(document.implementation && document.implementation.createDocument)
{
var xmlDom=document.implementation.createDocument( " ", "doc ",null);
}
}
xmlDom.async = false;
xmlDom.loadXML(XMLHttpReq.responseText);
var typeId = document.forms[0].typeId;
//清空select所有option选项
typeId.options.length = 0;
var smallTypes = xmlDom.getElementsByTagName( "smalltypes/smalltype ");
//包含子类信息
if(smallTypes.length != 0)
{
var option = document.createElement( "option ");
option.text = "未选择 ";
option.value = -1;
typeId.options.add(option);
for(var i = 0;i < smallTypes.length;i ++)
{
//子类ID
var typeIdText = smallTypes[i].firstChild.text;
//子类名
var typeNameText = smallTypes[i].lastChild.text;
//添加子类信息到下拉列表
var option = document.createElement( "option ");
option.text = typeNameText;
option.value = typeIdText;
typeId.options.add(option);
}
}
else
{
var option = document.createElement( "option ");
option.text = "无子类 ";
option.value = document.forms[0].bigTypeSelect.options(document.forms[0].bigTypeSelect.selectedIndex).value;
typeId.options.add(option);
}
}
else
{
alert( "Error data:\n "+ XMLHttpReq.statusText);
}
}
}
<html>
<head><title>select 与text测试页</title>
<script language=JavaScript>
function Love(ID,guige,mark,price)
{this.ID = ID;
this.guige = guige;
this.mark = mark;
this.price = price;
}
var Love_Array = Array(6);
Love_Array[0] = new Love("2","3*4*5 ","khgm ","120");
Love_Array[1] = new Love("4","8*7*6 ","贵贵 ","10000");
Love_Array[2] = new Love("5","有关 ","仍有 ","1234");
Love_Array[3] = new Love("7","33sss ","ww ","333");
Love_Array[4] = new Love("8","74 ","77 ","74");
Love_Array[5] = new Love("9","22 ","22 ","22");
function chec(love_id)
{
var love_shb = "";
var love_guige = "";
var love_price = "";
for (i = 0;i < Love_Array.length;i++)
{ if (Love_Array[i].ID == love_id)
{ love_shb = Love_Array[i].mark;
love_guige = Love_Array[i].guige;
love_price = Love_Array[i].price;
}
}
document.uform.shb.value = love_shb;
document.uform.guige.value = love_guige;
document.uform.danjia.value = love_price;
}
</script>
</head>
<body>
<center>
<form name="uform">
<table width=387>
<tr>
<td width="79">产品名称:</td>
<td width="296">
<select name="select" onchange="chec(this.options[this.selectedIndex].value);">
<option value=2>小 </option>
<option value=4>大的 </option>
<option value=5>刘少奇 </option>
<option value=7>www </option>
<option value=8>745 </option>
<option value=9>h221 </option>
</select>
</td>
</tr>
<tr>
<td width="79">产品商标:</td>
<td width="296">
<input name="shb" type="text" height=20>
</td>
</tr>
<tr>
<td width="79">产品规格:</td>
<td width="296">
<input name="guige" type="text" height=20>
</td>
</tr>
<tr>
<td width="79">产品单价:</td>
<td width="296">
<input name="danjia" type="text" height=20>
</td>
</tr>
<tr align="center">
<td colspan="2">
<input name="submit" type="submit" value="提交"></td>
</tr>
</table>
</form>
</center>
</body>
</html>