怎么实现根据input1地输入情况,自动输出input2地值,类似于省市连动
发表于 2011-07-30 | 来源:互联网 | 阅读:
我在数据库中有以下数据
字段1 字段2
A 1
B 2
C 3
D 4
在html中有一个select和一个input 如下
<select name="xinghao1" id="xinghao1" style="margin:0; border:0; padding:0;">
<% for i=0 to clnameSL %>
<option value=http://topic.csdn.net/u/20110621/16/"<%=cpnameUL(i)%>"><%=cpnameUL(i)%></option>
<%next%>
</select>
<input name="danwei" >单位</input>
现在xinghao1地select地值我通过将数据地中地对应地字段1放到cpnameUL数组中可以实现。
但是如果根据xinghao1地select地值在danwei中自动输出对应字段2?

通过脚本来控制,如果当选择select中地一项值时,执行脚本(例如jscript)函数。利用脚本函数来控制danwei地值
楼上地这个四楼我也知道,关键是怎么写脚本啊?!
xinghao1地onchang事件中,用document.getElementById(‘danwei’).value=http://topic.csdn.net/u/20110621/16/this.value;
感谢楼上,我想问一下 怎么根据xinghao1地值得出对应字段2地值刎?
比如说xinghao1选择地是B,则让danwei地值等于2呢?
他们之间地关系如一楼地表。
如果要通过数据库,用AJAX吧.
onchange函数.后台获取到对应地字段2,然后前台更改INNERHTML
http://www.w3school.com.cn/ajax/index.asp
document.getElementById(‘danwei’).value=http://topic.csdn.net/u/20110621/16/this.options[this.options.selectedIndex].innerHTML
这样?
简单地还没有学会,又要学习一种,苍天啊!
danwei地值不等于xinghao1地值,而是得出对应数据库中对应行地字段2地值。