将选项设置为从阵列下拉选择。

时间:2016-10-07 16:36:41

标签: html vbscript asp-classic

我使用经典ASP,我有一个数组,我循环,以填充下拉框。我试图这样做,当你提交表格时,它保持所选的价值。

<div class="input-group">
     <span class="input-group-addon" id="contactField1" >Name</span>
     <input type="text" class="form-control" required="true" placeholder="write Name" aria-describedby="contactField1">
</div>

1 个答案:

答案 0 :(得分:0)

尝试使用cint。默认情况下,查询字符串和表单变量被视为字符串,您需要告诉ASP将它们视为整数。

<select name="ID" style="border-width: 1px; width: 260px;" >


<%
                For idx = 1 to Ubound (g_Array)
                %>
                    <option value="<%=idx%>"
                    <% If cint(Request.Form("ID")) = idx Then Response.Write("selected") %>> <%=g_Array(idx)%>
                    </option>
                <%
                next
            %>
        </select>

请注意,您可以使用<%=idx%>作为<%response.Write(idx)%>

的缩写替代方案