我在Dreamweaver中使用ASP构建了一个HTML代码 如何将userID放入输入文本字段,将userTitle放入另一个输入文本字段,将userName放入表的另一个输入文本字段。它将所有三个作为组合文本返回到输入字段中。如何分开它们。请帮忙!
代码:
<HTML>
<%
Response.Buffer
infoDoc = ""
if Session("userTitle") <> "" and Session("userID")<> "" Then
infoDoc = "<option value '" & rs("userID) & "'" & rs("userName") & "'" & selections & ">" & rs("userTitle") </option>
Else
Session("userName") = ""
Session("userID") = 1
Session("userTitle") = ""
End If
sql= Select * From Users Order by userTitle
set rs= Conn.Execute(sql) Then
selections = "selected"
End If
infoDoc = infoDoc & "<option value '" & rs("userID) & "'" & rs("userName") & "'" & selections & ">" & rs("userTitle") </option>
rs.movement
selections = ""
Loop
rs.close
set rs=Nothing
%>
<table>
<tr>
<td> Select User</td>
<td><Select id=select onchange="myFunction()" name=select><% infoDoc %></Select></td>
<tr>ID
<td><input name=ID type=text id=ID disabled></td>
</tr>
<tr>Name
<td><input name=name type=text id=name disabled></td>
</tr>
<tr>ID
<td><input name=title type=text id=title disabled></td>
</tr>
</table>
<script>
function myFunction()
{
document.getElementByID("ID") = document.getElementByID("select").value
}
</script>
</HTML>
答案 0 :(得分:0)
试试这个:
function myFunction(thizz) {
var str = thizz.options[thizz.selectedIndex].text.split("your_separated_char");
if(str.length == 3) {
document.getElementById("ID").value = str[0];
document.getElementById("Name").value = str[1];
document.getElementById("title").value = str[2];
}
}
your_separated_char
可以是空白,逗号,点等......
更改为传递this
param是func的select元素,如下所示:
<td><Select id=select onchange="myFunction(this)" name=select><% infoDoc %></Select></td>