gpt4 book ai didi

javascript - 如何从选定的选项中获取值

转载 作者:行者123 更新时间:2023-11-28 10:41:59 25 4
gpt4 key购买 nike

我有一个包含 User_id、名字、姓氏和 Angular 色的用户表。我喜欢创建一个经典的 ASP 页面来在选择选项时显示值。每当我从下拉框中选择用户名时,它就会在下面显示其值。我尝试过,但当我在下拉列表中选择用户名时,它没有执行任何操作。

Here is my code:
User_id Firstname Lastname Role
-------------------------------------
1 Jenny Rogers A
2 Jenny2 Rogers2 B
1 Jenny Rogers B
2 Jenny2 Rogers2 A
3 Jenny3 Rogers3 C

ASP 代码:

<form action="" method="post" id="newMenu" name="frmReport" onSubmit="return validateForm(this)">
<table>
<thead>
<tr>
<td>
<strong>New User: </strong>
<select name="UserID">
<option value="">All Users</option>
<% sSQL = "SELECT DISTINCT User_id, Lastname, Firstname FROM User "
objRS.Open sSQL, objConn
Do Until objRS.EOF
Response.Write("<option value='" & objRS("User_id") & "'>" & objRS("Lastname") & ", " & objRS("Firstname") & "</option>")
objRS.MoveNext
Loop
objRS.Close
%>
</select>
<%
If Len("UserID") > 0 Then
sSQL = "SELECT User_id, Role FROM Users WHERE User_id = '" & request.Form("UserID") & "' ; "
objRS.Open sSQL, objConn
Do Until objRS.EOF
%>
<input type="text" name="Role" value="<%= objRS(" Role ") %>">
<% objRS.MoveNext
Loop
objRS.Close
End If
%>
<input type="hidden" name="FormSource" value="SubmitForm">
<input type="submit" value="Submit Form">
</th>
</tr>
</table>
</form>

最佳答案

也许这就是你想要的

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="Connections/BUYIN.asp" -->
<%
''''''Recordset with Names
Dim objRS
Dim objRS_cmd
Dim objRS_numRows

Set objRS_cmd = Server.CreateObject ("ADODB.Command")
objRS_cmd.ActiveConnection = MM_BUYIN_STRING
objRS_cmd.CommandText = "SELECT id, FirstName, LastName FROM dbo.BI_Users WHERE firstname like '%test%'"
objRS_cmd.Prepared = true

Set objRS = objRS_cmd.Execute
objRS_numRows = 0
%>
<!--Results -->
<% If Request.Form("selectID") <> "" Then %>
<%
Dim rsResults__getID
rsResults__getID = "0"
If (Request.Form("selectID") <> "") Then
rsResults__getID = Request.Form("selectID")
End If
%>
<%
Dim rsResults
Dim rsResults_cmd
Dim rsResults_numRows

Set rsResults_cmd = Server.CreateObject ("ADODB.Command")
rsResults_cmd.ActiveConnection = MM_BUYIN_STRING
rsResults_cmd.CommandText = "SELECT id, FirstName, LastName, fkRoleID FROM dbo.BI_Users WHERE id = ?"
rsResults_cmd.Prepared = true
rsResults_cmd.Parameters.Append rsResults_cmd.CreateParameter("param1", 5, 1, -1, rsResults__getID) ' adDouble

Set rsResults = rsResults_cmd.Execute
rsResults_numRows = 0
%>
<% End If %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="testasp2.asp">
<select name="selectID" id="selectID">
<%
While (NOT objRS.EOF)
%>
<option value="<%=(objRS.Fields.Item("id").Value)%>" <%If (Not isNull(Request.Form("selectID"))) Then If (CStr(objRS.Fields.Item("id").Value) = CStr(Request.Form("selectID"))) Then Response.Write("selected=""selected""") : Response.Write("")%> ><%=(objRS.Fields.Item("LastName").Value)%></option>
<%
objRS.MoveNext()
Wend
If (objRS.CursorType > 0) Then
objRS.MoveFirst
Else
objRS.Requery
End If
%>
</select>
<input type="submit" name="button" id="button" value="Submit" />
</form>
<hr />
<% If Request.Form("selectID") <> "" Then %>
<% If Not rsResults.EOF Or Not rsResults.BOF Then %>
<p><%=(rsResults.Fields.Item("id").Value)%> </p>
<p><%=(rsResults.Fields.Item("FirstName").Value)%> </p>
<p><%=(rsResults.Fields.Item("LastName").Value)%> </p>
<p><%=(rsResults.Fields.Item("fkRoleid").Value)%> </p>

<%
rsResults.Close()
Set rsResults = Nothing
%>
<% End If %>
<% Else %>
<%= "No Results Yet" %>
<% End If %>
</body>
</html>
<%
objRS.Close()
Set objRS = Nothing
%>

关于javascript - 如何从选定的选项中获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50491300/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com