<td width="176" height="25" class="style1场所名称</td>
<td colspan="3">
<select name="select">
(这里是一个jstl标签引用${a.compName})
</select></td>
<td width="143"> 场所负责人</td>
<td colspan="3"><input name="CompManager" type="text">
</td>
我的想法是这样的:上面的select有许多的值(当然"场所名称"与"场所负责人"来自同一张数据库表),当你选择一个值时(场所名称的),那个text自动显示相对应的值(场所负责人).
由于本人第一次学做项目,加之对script不太熟悉,请各位关照一下,不管用什么方法都行,只要能成功.非常感谢!
<td colspan="3">
<select name="select">
(这里是一个jstl标签引用${a.compName})
</select></td>
<td width="143"> 场所负责人</td>
<td colspan="3"><input name="CompManager" type="text">
</td>
我的想法是这样的:上面的select有许多的值(当然"场所名称"与"场所负责人"来自同一张数据库表),当你选择一个值时(场所名称的),那个text自动显示相对应的值(场所负责人).
由于本人第一次学做项目,加之对script不太熟悉,请各位关照一下,不管用什么方法都行,只要能成功.非常感谢!
Array selectContent = new Array("select1","select2","select3");
document.all.CompManager.value = selectContent(parseInt(document.all.select.selectedIndex));
}
然后把
<select name="select"> 改成<select name="select" onchange="onSelectChange()">
还望多多指教,谢谢!
写的很明白了
array 你不需要知道要多长,他是从数据库里面读出来的吧
selectContent(parseInt(document.all.select.selectedIndex));
是由select的位置得到所在数组里面的值
然后再赋给CompManager
我仔细看了上面的代码,但是我还是不明白怎么去解决啊
急啊,还忘指教,等待中.....................
<select name="select" size="1" onchange="onSelectChange()">
<option value="1" selected>select1</option>
<option value="2">select2</option>
<option value="3">select3</option>
</select>
<input type="text" name="CompManager">
</form>
<script>
function onSelectChange(){
var c = new Array("水煮鱼","鸡蛋面","豆腐")
document.all.CompManager.value = c[document.all.select.selectedIndex]
}
</script>我改的一个小例子你再看看
<tr>
<td width="176" height="25" class="style1"><div align="right" class="style6 style3"> 场所名称 </div></td>
<td colspan="3"><select name="CompName" onchange="onSelectChange()">
<c:forEach var="locationList" items="${locationList}">
<option value="${locationList.compName}">${locationList.compName}</option>
</c:forEach>
</select></td>
<td width="143"><div align="right" class="style6 style3"> 场所负责人 </div></td>
<td colspan="3"><div align="left" class="style3"><input name="managerName" type="text" id="id3" size="30" maxlength="50" style="border-color: #000099; border-style: double; border-width: 2px" value="">
</div></td>
</tr>
代码在上面,由于我用的是jstl+ArrayList 所以这个 Array selectContent = new ---Array("select1","select2","select3");怎么写啊---这是我写的(由于不是很懂)Array selectContent = new Array("${locationList.compName}");就出现了如下错:The "." operator was supplied with an index value of type "java.lang.String" to be applied to a List or array, but that value cannot be converted to an integer.
我觉得就是这个Array不能像我这样副值过去,敬请各位大哥在烦劳一下,帮帮我,非常感谢!
Array.push()
将一个或多个元素添加到数组的结尾,并返回该数组的新长度
selectContent = new Array()
selectContent.push(..)
(这里是一个jstl标签引用${a.compName})
</select></td>
select里面的从arraylist里面的一串值覆给function onSelectChange()这个方法呢?
Array selectContent = new Array("1","3","2");
//selectContent.push(document.all.CompName.value);
document.all.managerName.value = selectContent(parseInt(document.all.CompName.selectedIndex));
}
2.
<td width="143"><div align="right" class="style6 style3"> 场所负责人 </div></td>
<td colspan="3"><div align="left" class="style3"><input name="managerName" type="text" id="id3" size="30" maxlength="50" style="border-color: #000099; border-style: double; border-width: 2px" value="">
</div></td>
我这样子那"场所负责人"里面都没有值啊,到底是怎么回事
改下
selectContent = new Array("1","3","2");
或是 var selectContent = new Array("1","3","2");
document.all.managerName.value = selectContent[document.all.CompName.selectedIndex];要下班了 回来再看
feigme(泡沫微笑。o 0)刚刚改的onSelectChange()函数没问题,我已经试过,可以在文本框managerName中显示值,以下是改过的那个函数:function onSelectChange(){
var selectContent = new Array("1","2","3");
//selectContent.push(document.all.CompName.value);
document.all.managerName.value = selectContent[parseInt (document.all.CompName.selectedIndex)];
}