| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1101 人关注过本帖
标题:ASP动态添加文本框,一起写入数据库怎么实现,高手帮忙,谢谢!
只看楼主 加入收藏
my1127
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2011-6-5
结帖率:60%
收藏
已结贴  问题点数:0 回复次数:1 
ASP动态添加文本框,一起写入数据库怎么实现,高手帮忙,谢谢!
我想做一个动态添加文本框的页面,点击“增加”表格可以自动添加一行,同时添加一行文本框。最后统一“提交”写入到数据库里面的多条记录。动态添加的代码已经找到了,但是不知道怎么实现写入到ACCESS数据库里面去。哪位高手帮忙写一段最后能批量添加到ACCESS数据库的代码啊,十分感谢!
动态添加文本框的代码如下:
程序代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.">
<html xmlns="http://www.">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script language="JavaScript">
function addOrderRow(tab,rowNum,colNum,obj,addType)
{
var detailbody=document.getElementById(tab);
var row = document.createElement("tr");
var newrow=obj.parentNode.parentNode.innerHTML;
if(addType=='add'){
 var row = detailbody.insertRow();

 for(var i=0;i<obj.parentNode.parentNode.childNodes.length;i++){
  var cell=row.insertCell();
  cell.innerHTML=obj.parentNode.parentNode.childNodes[i].innerHTML;
  //alert(obj.parentNode.parentNode.childNodes[i].innerHTML);
  //如果表单中有值就清空
  for(var k=0;k<cell.childNodes.length;k++){
   if (cell.childNodes[k].type == 'text') { cell.childNodes[k].value = ''; }
   if (cell.childNodes[k].type == 'textarea') { cell.childNodes[k].value = ''; }
   if (cell.childNodes[k].type == 'checkbox') { cell.childNodes[k].checked = false; }
   if (cell.childNodes[k].type == 'radio') { cell.childNodes[k].checked = false; }
   if (cell.childNodes[k].type == 'select-multiple') { cell.childNodes[k].selectedIndex = -1; }
   if (cell.childNodes[k].type == 'select-one') { cell.childNodes[k].selectedIndex = -1; }
  }
  //cell.innerHTML=arr[i];

 }
  obj.parentNode.parentNode.childNodes[0].innerHTML+='<input type=hidden id=text'+(detailbody.childNodes.length+1)+'>';
}else if(addType=='copy'){
//copy
//detailbody.insertRow().insertCell().innerHTML = newrow;   ok
var row = detailbody.insertRow();
for(var i=0;i<obj.parentNode.parentNode.childNodes.length;i++){
var cell=row.insertCell();
cell.innerHTML=obj.parentNode.parentNode.childNodes[i].innerHTML;
}
obj.parentNode.parentNode.childNodes[0].innerHTML+='<input type=hidden id=text'+(detailbody.childNodes.length+1)+'>';
}else{
//delete
if(confirm("Are you sure to delete this record?")){
    obj.parentNode.parentNode.parentNode.removeChild(obj.parentNode.parentNode);
}else{
return false;
}
}
//只显示最后一个add按钮
var leg = detailbody.childNodes.length;
if(leg>1){
for(var j=0;j<leg-2;j++){
document.getElementsByName("btnAdd")[j].style.visibility="hidden";
}
  document.getElementsByName("btnAdd")[leg-2].style.visibility="visible";
  //document.getElementsByName("btnDelete")[0].style.visibility="hidden";
   }
//显示除第一个外所有delete按钮
if(leg>1){
  for(var j=1;j<leg-1;j++){
document.getElementsByName("btnDelete")[j].style.visibility="visible";
}
}
        }
</script>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
<div id="outlineChildaaa" style="cursor:auto" >
<table width="700" border="1" cellpadding="5" cellspacing="0" bordercolor="#E8E09F"  id="detailItem">
  <tbody id="detailItemBody">
  <tr>
    <td width="38%" nowrap="" bgcolor="#F3EFCD" class="STYLE7 td1"><strong>名称</strong></td>
    <td width="19%" nowrap="" bgcolor="#F3EFCD" class="STYLE7 td1"><strong>颜色</strong></td>
    <td width="10%" nowrap="" bgcolor="#F3EFCD" class="STYLE7 td1"><strong>数量</strong></td>
    <td width="10%" nowrap="" bgcolor="#F3EFCD" class="STYLE7 td1"><strong>排序</strong></td>
    <td width="23%" bgcolor="#F3EFCD" class="td1 STYLE7"><strong>操作</strong></td>
  </tr>
  <tr id="tr1">
    <td width="38%" id="td1" >
<input type="hidden" name="SampleOrderContentID"/>
<input type="text" size="30" name="name" id="ItemNo"/></td>
    <td width="19%" nowrap=""><input type="text" size="10" name="color" id="ItemNo1"/></td>
    <td width="10%" nowrap=""><input type="text" size="6" name="quantity" id="Nickname1"/></td>
    <td width="10%" nowrap=""><input type="text" size="6" name="px" id="cleats1"/></td>
    <td width="23%" nowrap="">
<input type="button" onclick="addOrderRow('detailItemBody',2,11,this,'add')" value="增加" id="btnAdd1" name="btnAdd"/>
<input type="button" onclick="addOrderRow('detailItemBody',2,11,this,'copy')" value="复制" id="btnCopy" name="btnCopy"/>
<input type="button" onclick="addOrderRow('detailItemBody',2,11,this,'delete')" value="删除" id="btnDelete" name="btnDelete" style="visibility:hidden "/></td>
  </tr>
</tbody>
</table>
    <table width="700" border="0">
      <tr>
        <td><div align="center">
          <label>
          <input type="submit" name="Submit" value="提交" />
          </label>
        </div></td>
      </tr>
    </table>
  </div>
</form>
</body>
</html>

搜索更多相关主题的帖子: 数据库 文本框 
2011-06-05 21:55
yms123
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:209
帖 子:12488
专家分:19042
注 册:2004-7-17
收藏
得分:20 
程序代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.>
<html xmlns="http://www.>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script language="JavaScript">
function addOrderRow(tab,rowNum,colNum,obj,addType)
{
var detailbody=document.getElementById(tab);
var row = document.createElement("tr");
var newrow=obj.parentNode.parentNode.innerHTML;
if(addType=='add'){
var row = detailbody.insertRow();
for(var i=0;i<obj.parentNode.parentNode.childNodes.length;i++){
  var cell=row.insertCell();
  cell.innerHTML=obj.parentNode.parentNode.childNodes[i].innerHTML;
  //alert(obj.parentNode.parentNode.childNodes[i].innerHTML);
  //如果表单中有值就清空
  for(var k=0;k<cell.childNodes.length;k++){
   if (cell.childNodes[k].type == 'text') { cell.childNodes[k].value = ''; }
   if (cell.childNodes[k].type == 'textarea') { cell.childNodes[k].value = ''; }
   if (cell.childNodes[k].type == 'checkbox') { cell.childNodes[k].checked = false; }
   if (cell.childNodes[k].type == 'radio') { cell.childNodes[k].checked = false; }
   if (cell.childNodes[k].type == 'select-multiple') { cell.childNodes[k].selectedIndex = -1; }
   if (cell.childNodes[k].type == 'select-one') { cell.childNodes[k].selectedIndex = -1; }
  }
  //cell.innerHTML=arr[i];
}
  obj.parentNode.parentNode.childNodes[0].innerHTML+='<input type=hidden id=text'+(detailbody.childNodes.length+1)+'>';
}else if(addType=='copy'){
//copy
//detailbody.insertRow().insertCell().innerHTML = newrow;   ok
var row = detailbody.insertRow();
for(var i=0;i<obj.parentNode.parentNode.childNodes.length;i++){
var cell=row.insertCell();
cell.innerHTML=obj.parentNode.parentNode.childNodes[i].innerHTML;
}
obj.parentNode.parentNode.childNodes[0].innerHTML+='<input type=hidden id=text'+(detailbody.childNodes.length+1)+'>';
}else{
//delete
if(confirm("Are you sure to delete this record?")){
    obj.parentNode.parentNode.parentNode.removeChild(obj.parentNode.parentNode);
}else{
return false;
}
}
//只显示最后一个add按钮
var leg = detailbody.childNodes.length;
if(leg>1){
for(var j=0;j<leg-2;j++){
document.getElementsByName("btnAdd")[j].style.visibility="hidden";
}
  document.getElementsByName("btnAdd")[leg-2].style.visibility="visible";
  //document.getElementsByName("btnDelete")[0].style.visibility="hidden";
   }
//显示除第一个外所有delete按钮
if(leg>1){
  for(var j=1;j<leg-1;j++){
document.getElementsByName("btnDelete")[j].style.visibility="visible";
}
}
        }
function Page_Load()
{
<%
   Dim con
   Set con=Server.CreateObject("ADODB.Connection")
   con.ConnectionString="这里写数据库连接字符串"
   con.ConnectionTimeOut=30
   con.Open
   IF Request.Form("isSubmit")="True" Then
      Dim i,rs
      Set rs=Server.CreateObject("ADODB.RecordSet")
      rs.Open "这里写要添加的数据表名称",con,1,3
      For i=0 To Request.Form("name").Count
          rs.AddNew
          rs("name")=Request.Form("name")(i)
          rs("color")=Request.Form("color")(i)
          rs("quantity")=Request.Form("quantity")(i)
          rs("px")=Request.Form("px")(i)
          rs.Update
      Next
   End IF
   rs.Close
   con.Close
   Set con=Nothing
   Set rs=Nothing
   Response.Write "alert('添加成功');"
%>
}
</script>
</head>

<body onload="Page_Load()">
<form id="form1" name="form1" method="post" action="">
<div id="outlineChildaaa" style="cursor:auto" >
<table width="700" border="1" cellpadding="5" cellspacing="0" bordercolor="#E8E09F"  id="detailItem">
  <tbody id="detailItemBody">
  <tr>
    <td width="38%" nowrap="" bgcolor="#F3EFCD" class="STYLE7 td1"><strong>名称</strong></td>
    <td width="19%" nowrap="" bgcolor="#F3EFCD" class="STYLE7 td1"><strong>颜色</strong></td>
    <td width="10%" nowrap="" bgcolor="#F3EFCD" class="STYLE7 td1"><strong>数量</strong></td>
    <td width="10%" nowrap="" bgcolor="#F3EFCD" class="STYLE7 td1"><strong>排序</strong></td>
    <td width="23%" bgcolor="#F3EFCD" class="td1 STYLE7"><strong>操作</strong></td>
  </tr>
  <tr id="tr1">
    <td width="38%" id="td1" >
<input type="hidden" name="SampleOrderContentID"/>
<input type="text" size="30" name="name" id="ItemNo"/></td>
    <td width="19%" nowrap=""><input type="text" size="10" name="color" id="ItemNo1"/></td>
    <td width="10%" nowrap=""><input type="text" size="6" name="quantity" id="Nickname1"/></td>
    <td width="10%" nowrap=""><input type="text" size="6" name="px" id="cleats1"/></td>
    <td width="23%" nowrap="">
<input type="button" onclick="addOrderRow('detailItemBody',2,11,this,'add')" value="增加" id="btnAdd1" name="btnAdd"/>
<input type="button" onclick="addOrderRow('detailItemBody',2,11,this,'copy')" value="复制" id="btnCopy" name="btnCopy"/>
<input type="button" onclick="addOrderRow('detailItemBody',2,11,this,'delete')" value="删除" id="btnDelete" name="btnDelete" style="visibility:hidden "/></td>
  </tr>
</tbody>
</table>
    <table width="700" border="0">
      <tr>
        <td><div align="center">
          <label>
          <input type="submit" name="Submit" value="提交" />
          <input type="hidden" mame="isSubmit" value="True" />
          </label>
        </div></td>
      </tr>
    </table>
  </div>
</form>
</body>
</html>

2011-06-08 11:05
快速回复:ASP动态添加文本框,一起写入数据库怎么实现,高手帮忙,谢谢!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.047372 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved