【问题标题】:ASP/HTML Dynamic Checkbox GroupsASP/HTML 动态复选框组
【发布时间】:2014-08-02 11:53:59
【问题描述】:

我正在生成一个页面,该页面需要从数据库中提取可变数量的条目,然后使用复选框将数据添加到数据库中的另一个表中。

基本上,我将从数据库中提取名称列表,然后将有 4 个是/否条件添加到每个条目中,结果将被发送到另一个数据库。

这就是我现在拥有的:

<%
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.open "--connection information here--"
SQL = "Select firstname,lastname from [names] order by lastname"
Set RS = Conn.Execute(SQL)
%>
<table border=1>
  <tr>
    <th>Name</th>
    <th>Condition One</th>
    <th>Condition Two</th>
    <th>Condition Three</th>
    <th>Condition Four</th>
  </tr>
  <% Do While Not RS.EOF %>
  <tr>
    <td><%=RS("LastName")%>, <%=RS("FirstName")%></td>
    <td><input type="checkbox"></td>
    <td><input type="checkbox"></td>
    <td><input type="checkbox"></td>
    <td><input type="checkbox"></td>
  </tr>
  <%
    RS.MoveNext
    Loop
  %>
</table>

我知道我没有任何复选框的标识属性,例如 name 或 id,这是因为我不确定如何在循环中动态执行此操作,以便将数据组合在一起我需要它的方式。另外请忽略我在上面的代码中可能犯的任何语法错误,我重新输入了这个而不是复制/粘贴我的实际代码,这样我可以使它更具可读性并保护敏感信息,同时向您展示我正在使用的内容。实际页面使用与上面完全相同的格式和结构,并且可以正常工作。

这会生成看起来像我想要的页面,但我需要返回并检索包含名称和相应条件的组中的信息,以便我可以在第二个表中的正确位置输入信息。

我如何标记或构造它以便提取我需要的信息?

现在,我找到了发布 [https://stackoverflow.com/questions/11246140/variable-number-of-categories-checkboxes] 的问题,但唯一的答案是使用外部脚本。我需要能够在不包括我正在从事的项目的外部脚本的情况下做到这一点。

【问题讨论】:

  • 您有针对 [Names] 的 ID 吗?
  • 对不起,我不太明白你在问什么……
  • 在您的姓名表中..您有 ID 字段吗?
  • 抱歉耽搁了,真的很忙。是的,我确实有一个 ID 字段,它是表格的键,并在添加新条目时自动递增。

标签: html dynamic checkbox asp-classic


【解决方案1】:
<%
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.open "--connection information here--"
SQL = "Select ID,firstname,lastname from [names] order by lastname"
Set RS = Conn.Execute(SQL)
%>
<table border=1>
  <tr>
    <th>Name</th>
    <th>Condition One</th>
    <th>Condition Two</th>
    <th>Condition Three</th>
    <th>Condition Four</th>
  </tr>
  <% Do While Not RS.EOF %>
  <tr>
    <td><%=RS("LastName")%>, <%=RS("FirstName")%></td>
    <td><input type="checkbox" name="Cond_1_<%=RS("ID")%>"></td>
    <td><input type="checkbox" name="Cond_2_<%=RS("ID")%>"></td>
    <td><input type="checkbox" name="Cond_3_<%=RS("ID")%>"></td>
    <td><input type="checkbox" name="Cond_4_<%=RS("ID")%>"></td>
  </tr>
  <%
    RS.MoveNext
    Loop
  %>
</table>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多