0

我正在尝试创建一个单选按钮列表,当用户选择一个选项时,会显示与他们选择另一个单选按钮不同的表单。例如,如果他们选择“添加类别”,则将显示关联的表单,但如果他们选择“删除类别”,则会显示允许他们删除类别的表单。

目前,我正在使用一个名为“stage”的变量,并通过将 stage 设置为不同的数值来完成整个过程,因为它们通过每个表单的隐藏数据传递。不幸的是,除了第 2 阶段的表格外,我无法让它显示任何内容。

<% option explicit %>
<html>
<head>
</head>
<body>
<!--#include file="dbconn.asp"-->
<!--#include file="header.asp"-->

    <div class="content">

<div class="content-inner container_12">

  <div class="wrapper prefix_2 grid_8 suffix_2">
<%

  dim stage, SQL, info 
  stage = request.form("stage")
  if stage = "" then stage=1

  '------------------------------------------------------------------
  if stage = 1 then
  '------------------------------------------------------------------

'                     0     1       
         SQL="select ID, category "&_
             "from categorytable "&_
             "order by category DESC"

        set info=conn.execute(SQL) 

        if info.eof then

          response.write "<p>There are no categories</p>"

        end if

    '--- create a radio-button list of the current posts
    response.write "<form id=""categoryedit""action=""category.asp"" method=""post"">" &_
                   "<input type=""hidden"" name=""stage"" value =""2"">"&_
                   "<label for=""addcategory"">Add Category</label>"&_
                   "<input id=""addcategory"" type=""radio"" name=""addcategory"" value=""stage = 2""><br>" &_
                   "<label for=""deletecategory"">Delete Category</label>"&_
                   "<input id=""deletecategory"" type=""radio"" name=""deletecategory"" value="" stage = 4""><br>" &_
                   "<label for=""editcategory"">Edit Category</label>"&_
                   "<input id=""editcategory"" type=""radio"" name=""editcategory"" value="" stage = 6""><br>" &_
                   "<input class=""button"" type=""submit"" value=""Select"">" &_
                   "</form>" 

  '------------------------------------------------------------------
  elseif stage = 2 then
  '------------------------------------------------------------------

  response.write "<form action=""category.asp"" method=""post"">" &_
                   "<input type=""hidden"" name=""stage"" value =""3"">"&_
                   "<label for ""category"">New Category</label>"&_
                   "<input type=""text"" id=""category"" name=""newcategory"" required><br>"&_
                   "<input class=""button"" type=""submit"" value=""Add Category"">"&_
                   "</form>"



    '------------------------------------------------------------------
  elseif stage = 3 then
  '------------------------------------------------------------------

     dim category 
      category = request.Form("newcategory")

  sql = "insert into categorytable (category) "&_
        "values ('" & category & "')"
        conn.execute sql

      response.write "<p>New Category added.</p>"


  '------------------------------------------------------------------
  elseif stage = 4 then
  '------------------------------------------------------------------
   '              0     1       
         SQL="select ID, category "&_
             "from categorytable "&_
             "order by category DESC"

        set info=conn.execute(SQL) 


  response.write   "<form action=""category.asp"" method=""post"">" &_
                   "<input type=""hidden"" name=""stage"" value =""5"">"&_
                   "<label for ""category"">Delete Category</label>"
                   do
    response.write "<label for=""radio""></label>"&_
                   "<input id=""radio"" type=""radio"" name=""categorytobedeleted"" value=""" &_
                    info(0) & """>" &_
                    info(1) & "<br>"

   info.movenext
    loop until info.eof
    response.write  "<input class=""button"" type=""submit"" value=""Delete Category"">"&_
                   "</form>"

   '------------------------------------------------------------------
  elseif stage = 5 then
  '------------------------------------------------------------------

  dim deleteCategory
  deleteCategory = Request.Form("categorytobedeleted")
  sql = "delete * from categorytable where ID= "& deleteCategory 
conn.execute(sql)
  response.write  "<p>Category deleted.</p>" 

'------------------------------------------------------------------
  elseif stage = 6 then
  '------------------------------------------------------------------
 '              0     1       
         SQL="select ID, category "&_
             "from categorytable "&_
             "order by category DESC"

        set info=conn.execute(SQL) 


  response.write   "<form action=""category.asp"" method=""post"">" &_
                   "<input type=""hidden"" name=""stage"" value =""7"">"&_
                   "<label for ""category"">Edit Category</label>"
                   do
    response.write "<label for=""radio""></label>"&_
                   "<input id=""radio"" type=""radio"" name=""categorytobeedited"" value=""" &_
                    info(0) & """>" &_
                    info(1) & "<br>"

   info.movenext
    loop until info.eof
    response.write  "<input class=""button"" type=""submit"" value=""Edit Category"">"&_
                   "</form>"

  '------------------------------------------------------------------
  elseif stage = 7 then
  '------------------------------------------------------------------
  dim record_num
  record_num=Request.Form("categorytobeedited")
  if record_num="" then response.redirect "?pg=category"

    '                 0             1                                             
  SQL=  "SELECT categorytable.ID, category "&_
        " FROM CategoryTable"&_
        " WHERE categorytable.ID= "&record_num

  set info=conn.execute(SQL)
%>
        <form action="category.asp" method="post">
        <input type="hidden" name="stage" value="8">
        <input type="hidden" name="categorytable.ID" value="<% =record_num %>">
        <label for="category">Category</label>
        <input id="category" type="text" name="title" value="<% =info(1) %>"><br>
        <input id="edit" class="button" type="submit" value="Edit">
        </form>

<%

 '------------------------------------------------------------------
  elseif stage = 8 then
  '------------------------------------------------------------------

  dim addcategory
  addcategory = request.form("categorytable.ID")

  sql="update categorytable set category='"& addcategory & "'" &_
      "where categorytable.ID= "& addcategory

      conn.execute sql

       response.write "<p>Category edited.</p>"


  '------------------------------------------------------------------
  end if  ' stage
  '------------------------------------------------------------------

  if stage = 8  then
    response.write "<a href=""category.asp"">Show Categories</a>"

    end if
  conn.close 
%>

  </div>

</div>

</div>


<!--#include file="footer.asp"-->
</body>
</html>
4

1 回答 1

1

这部分看起来不对。一组单选按钮应共享相同的变量名称。更改单选按钮的名称,使其全部命名为“stage”。删除名为“stage”的隐藏字段,并将单选按钮的值设置为数字值。

response.write "<form id=""categoryedit""action=""category.asp"" method=""post"">" &_
               "<input type=""hidden"" name=""stage"" value =""2"">"&_
               "<label for=""addcategory"">Add Category</label>"&_
               "<input id=""addcategory"" type=""radio"" name=""addcategory"" value=""stage = 2""><br>" &_
               "<label for=""deletecategory"">Delete Category</label>"&_
               "<input id=""deletecategory"" type=""radio"" name=""deletecategory"" value="" stage = 4""><br>" &_
               "<label for=""editcategory"">Edit Category</label>"&_
               "<input id=""editcategory"" type=""radio"" name=""editcategory"" value="" stage = 6""><br>" &_
               "<input class=""button"" type=""submit"" value=""Select"">" &_
               "</form>" 

正确的代码应该是这样的

  <form id="categoryedit" action="category.asp" method="post">
      <label for="addcategory">Add Category</label>
      <input id="addcategory" type="radio" name="stage" value="2"><br>
      <label for="deletecategory">Delete Category</label>
      <input id="deletecategory" type="radio" name="stage" value="4"><br>
      <label for="editcategory">Edit Category</label>
      <input id="editcategory" type="radio" name="stage" value="6"><br>
      <input class="button" type="submit" value="Select">
  </form>
于 2013-11-04T09:15:40.437 回答