获取ASP服务器端所选复选框值的数组

Getting array of selected checkbox values in ASP server side

本文关键字:数组 复选框 ASP 服务器端 获取      更新时间:2023-09-26

我有一个有3个复选框的表单,我需要根据所选的复选框值执行一些操作。因此,我当前的任务是使用JScript在服务器端获取选定值的数组。这是一个表单

<form method ="post" action="table.asp" name="grades">
<input type="checkbox" value="2" name="cb" id="cb"> 2</input>
<br>
<input type="checkbox" value="3" name="cb" id="cb"> 3</input>
<br>
<input type="checkbox" value="4" name="cb" id="cb"> 4</input>
<br>
<input type ="submit" value=" Go">
</form>

我已经设法得到一个字符串看起来像cb=2&cb=3使用var cbstring = Request.form()

似乎我不能分割它与cbstring.split()方法。当我添加它时,服务器返回未指定的错误消息,没有任何有用的信息。在web.config中将Debug设置为true。

因此,任何帮助使事情正确将非常感谢

Request.Form是一个对象(ASP的请求字典),所以它没有split方法。幸运的是,Request.Form[(key)].Item是一个序列化的键或集合的键/值对的字符串。
看看https://stackoverflow.com/a/31444907/893670,看看如何在ASP/JScript中处理请求集合,它可能会有所帮助。
这是一个你想做的事情的方法。

var arr = [];
if(Request.Form("cb").Item)
    arr = Request.Form("cb").Item.split(", ");