html5中文学习网

您的位置: 首页 > 网络编程 > ASP编程 » 正文

ASP实现动态添加表单内容的实例程序_ASP教程_编程技术

[ ] 已经帮助:人解决问题
程序|动态

  很多时候,不知道需要表单的数目,就需要能对表单进行数量的控制。收集了如下两个效果:

  效果1:

    [Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]

  效果2:

    [Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]

在asp中,动态表单可按普通表单一样进行提交。简易的方法是设定一个固定表单的name,当有多个表单提交时,各表单数据会自动用","隔开,然后用split进行分割,再循环进行分别提交。如下:   

 <%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<script language="javascript">
function addTxtProductNameBox()
  {
      var oTb = document.getElementById("TableProductName");
      var oTr = oTb.insertRow(0);
      oTr.insertCell(0).innerHTML ="<input name='txtProductName' type='text'><input type=button >"
      return false;
  }
  function delTxtProductNameBox(obj)
  {
      obj.parentElement.parentElement.removeNode(true);
      return false;
  }
</script>
<% dim rs3,sql3,productNameArray
    if productName<>"" then
    set rs3=server.CreateObject ("ADODB.RecordSet")
    sql3="select * from AmdiProduct"
    rs3.open sql3,conn,3,2
    productNameArray=split(productName,",")
    for i = 0 to ubound(productNameArray)
    rs3.addnew
    rs3("CompanyID")=companyId
    rs3("ProductName")=productNameArray(i)
    rs3.update
    next
    rs3.close   
                set rs3=nothing
    end if
%>
<form name="form1" method="post" action="">
产品名称:<a href="#" >添加产品名称</a>
<table id="TableProductName" border=0>
   <tr><td> </td></tr>
</table>
<input name="submit" type="submit" id="submit" value="== 提交 ==" />
</form>

t3XHTML5中文学习网 - HTML5先行者学习网
t3XHTML5中文学习网 - HTML5先行者学习网
(责任编辑:)
推荐书籍
推荐资讯
关于HTML5先行者 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 人才招聘 - 帮助