我的asp文件中有一个隐藏字段,并且已经通过使用JavaScript函数为该隐藏字段分配了值。但是,我无法获得价值。

我必须获取隐藏字段值并传递给查询。

我的JS代码:

function checkboxlimit() {
    for (j = 0; j < checkboxes.length; j++)
    {
        if (checkboxes[j].checked == true)
        {
            alert(checkboxes[j].value)// this one coming?
            document.getElementById("Hidden1").value = checkboxes[j].value
            alert("Check" +document.getElementById("Hidden1").value)
        }
    }
}


HTML和ASP:

Do Until RS.EOF%>
<tr>
    <td valign="middle" align="center" class="style1">
        <input  type="checkbox" name="CompanyID_Merge" value="<%=RS("CompanyID")%>" onchange="checkboxlimit();" />
    </td>
    <td valign="middle" align="center"  class="style1">
        <a href="/main/league_info/companies/company_info.asp?CompanyID=<%=RS("CompanyID")%>"target="_blank"><%=RS("CompanyName")%></a>
    </td>
</tr>
<%
    RS.MoveNext
Loop
%>
</table>
<%
End If
RS.Close
SET RS = Nothing
Conn.Close
%>
<input id="Hidden1" type="hidden" name="CompanyID_hidden" runat="server" value=""/>
<%
    CompanyID_Merge=Request.Form("CompanyID_hidden")
    Response.Write("chk" & Request.Form("CompanyID_hidden"))
    Conn.Open strConn
    SQL = "SELECT"
    SQL = SQL & " Projects.CompanyID, Projects.ProjectID, Projects.ProjectName, Projects.SeasonYear, Seasons.Season, Activities.ActivityName,"
    SQL = SQL & " FROM Projects"
    SQL = SQL & " AND ProjectAssociations.RenewedProjectID = " & CheckNumber(ProjectID)
    SQL = SQL & " WHERE Projects.CompanyID = " & CheckNumber(CompanyID_Merge)

最佳答案

仅在提交表单或使用AJAX之后,才能在服务器端获取值。

就是说,您无需将复选框值分配给隐藏字段,您可以使用以下名称获取经典ASP中所有选定复选框的值:

<%
    Response.Write("selected " & Request.Form("CompanyID_Merge").Count & " items<br />")
    For x=1 To Request.Form("CompanyID_Merge").Count
        Response.Write(Request.Form("CompanyID_Merge").Item(x) & "<br />")
    Next
%>

10-07 14:20