为什么 ASP 经典中没有传递下拉值?

Why is dropdown value not being passed in ASP classic?

我试图将 newbrand 下拉列表中的值传递到下一页 (addbrand.asp),但是,它不起作用,只会是空白。谁能指出我正确的方向来解决这个问题?

<form class="form" method="post">
<table>
<%i = 0%>
<% for each brand in Brands %>
    <tr><td><B><%=brand%></B></td>  
    <td><input type="button" class="btn btn-small" value="Delete" onclick="document.location='deletebrand.asp?brand=<%=brands(i)%>&client=<%=clientcno%>&id=<%=clientid%>'"></td></tr>
    <%i = i + 1%>
<% next %>
<tr><td colspan=2><hr></td></tr>
<tr><td><B>Add:</B></td>
<td>
<select name="newbrand">
<option value=""></option>
<% for each brand in newbrands %>
    <option value="<%=brand%>"><%=brand%></option>
<% next %>
</select>
<%
If Request.Form("newbrand") <> "" then
    newbrand = Request.Form("newbrand")
End If
%>
<input type="button" class="btn btn-small" value="Add"
 onclick="document.location='addbrand.asp?brand=<%=newbrand%>&client=<%=clientcno%>&id=<%=clientid%>'");">
</td></tr>
</table>
</form>

如果您按下按钮 'add',它应该将 selected 'newbrand' 发送到 addbrand.asp?

现在您传递服务器端值,您需要发送客户端值。将 onclick 更改为

document.location='addbrand.asp?brand=' + document.getElementsByName("newbrand")[0].options[document.getElementsByName("newbrand")[0].selectedIndex].value + '&client=...

由于内联Javascript,它变得有点混乱。为 select 元素分配一个 ID 更容易,然后您可以使用 document.getElementById 这使它更简单一些:

document.location='addbrand.asp?brand=' + document.getElementById("newbrand").options[document.getElementById("newbrand").selectedIndex].value + '&client=...