从选择选项下拉列表中获取部分值

Get part of the value from a select option drop down?

本文关键字:获取部 下拉列表 选择 选项      更新时间:2023-09-26

我有一个HTML代码内置在Dreamweaver利用ASP如何将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>

试试这个:

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参数作为select元素传递给函数,如下所示:

<td><Select id=select onchange="myFunction(this)" name=select><% infoDoc %></Select></td>