首页 > 其他分享 >动态增加表单方法--ff/ie

动态增加表单方法--ff/ie

时间:2023-04-28 22:35:23浏览次数:31  
标签:objs return -- pid alert values ff sql ie


---------------------增加方法----------------------------

<h3><center>批量增加评论</center></h3><BR>
<form action="" method="post" οnsubmit="return check_form();">
<input type="button" value="增加一组评论输入栏" οnclick="insert_input();"/>  
<input type="submit" value="保存"/>
<BR>
<BR><div id=input_div></div>
<BR>
<BR><input type="button" value="增加一组评论输入栏" οnclick="insert_input();"/>  
<input type="submit" value="保存"/>
</form><script>
function check_form()
{
  if (objs('author[]').length < 1 )
  {
    alert('未有评论内容,不必提交');
    return false;
  }
  
  for (var for_i = 0; for_i < objs('author[]').length; for_i++)
  {
     if (/^ *$/.test(objs('author[]')[for_i].value) )
     {
       alert('第' + (for_i + 1 ) + '组评论用户未填写');
       objs('author[]')[for_i].focus();
       return false;
     }
     if (!/^[1-9]/d*$/.test(objs('agree[]')[for_i].value) )
     {
       alert('第' + (for_i + 1 ) + '组评论支持人数未填写(必须是数字)');
       objs('agree[]')[for_i].focus();
       return false;
     }
     if (/^ *$/.test(objs('title[]')[for_i].value) )
     {
       alert('第' + (for_i + 1 ) + '组评论标题未填写');
       objs('title[]')[for_i].focus();
       return false;
     }
     if (/^ *$/.test(objs('content[]')[for_i].value) )
     {
       alert('第' + (for_i + 1 ) + '组评论内容未填写');
       objs('content[]')[for_i].focus();
       return false;
     }
     if (/^ *$/.test(objs('back[]')[for_i].value) )
     {
       alert('第' + (for_i + 1 ) + '组评论回复未填写');
       objs('back[]')[for_i].focus();
       return false;
     }
  }
  
  return true;
}function obj(the_id)
{
  return document.getElementById(the_id);
}function objs(the_id)
{
  return document.getElementsByName(the_id);
}function insert_input()
{
   if (!window.comment_l) window.comment_l =1;
   
   var obj_h = document.createElement("div");
   obj_h.innerHTML = '第' + window.comment_l + '组评论栏<BR><BR>名字:<input id="author[]" name="author[]" style="width:100px;"> ' +
                   '支持人数:<input id="agree[]" name="agree[]" ><BR>' +
                   '标题:<input id="title[]" name="title[]" style="width:500px;"><BR>' + 
                   '评论:<textarea id="content[]" name="content[]" style="width:500px;height:50px;"></textarea><BR>' + 
                   '回复:<textarea id="back[]" name="back[]" style="width:500px;height:50px;"></textarea><BR><BR>';
  obj('input_div').appendChild(obj_h);
  window.comment_l++;
  
}
</script>

---------------------增加方法--------------

 

 

------------------数据库保存方法------------------

 

if( isset($_POST['content']) )
{
 $pid = $_GET['pid'];
 $for_i = 0;
 $sql_values = '';
 $strtest="/select|update|delete|insert/i";
 
 do
 {
  $sql_values .= ($for_i == 0?'(':',(');//不是第一组时,增加隔开符
 $sql_values .= "'". preg_replace($strtest,"",htmlspecialchars($_REQUEST['author'][$for_i])) ."'";//名称
 $sql_values .= ", '". preg_replace($strtest,"",htmlspecialchars($_REQUEST['title'][$for_i])) ."'";//标题
 $sql_values .= ", '". preg_replace($strtest,"",htmlspecialchars($_REQUEST['content'][$for_i])) ."'";//内容
 $sql_values .= ", '". preg_replace($strtest,"",htmlspecialchars($_REQUEST['back'][$for_i])) ."'";//回复
 $sql_values .= ", '". preg_replace($strtest,"",htmlspecialchars($_REQUEST['agree'][$for_i])) ."'";//支持
 $sql_values .= ",'$pid','".date("Y-m-d H:i:s")."','".date("Y-m-d H:i:s")."','".$_SERVER['REMOTE_ADDR']."','1')";//商品,时间,发表时间,ip,启用
 $for_i++;
 }while ($for_i < count($_POST['content']));
 
 $insert = "insert into ".TABLE.REVIEWS."(`author`,`title`,`content`,`back`,`agree`,`p_id`,`time`,`stime`,`ip`,`enable`) values $sql_values ";
 //echo $insert;
 $result=$db->query($insert);
 
 if($result)
 {
  $say = '评论发送成功!';
  $search = '?pid='.$pid.'&show_create=1';
 }
 else
 {
  $say = '评论发送失败!';
  $search = '?pid='.$pid;
 }  echo "<script>alert('$say');window.location.href='".$php_url."/bsh_syadmin/comment_by_us.php$search';</script>";
}------------------

-------------数据库保存方法------------------

 

 

 

这是为一个商场管理后台增加功能;

 

 

 

标签:objs,return,--,pid,alert,values,ff,sql,ie
From: https://blog.51cto.com/u_252283/6235716

相关文章

  • css3效果真Nb,可惜的ie
    <!DOCTYPEHTMLPUBLIC"-//W3C//DTDXHTML1.1//EN""http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><head><metahttp-equiv="Content-Type"content=&quo......
  • MFC-CListCtrl-InsertItem插入一行(一项)
     方式一inti1=mylist4.InsertItem(0,_T("李明"));//插入一行(一项)/*参数1:intnItem行的索引参数2:LPCTSTRlpszItem控件头的名字返回值:行号四种风格都可以*/     ......
  • 不跳动(除了ie6) 总在最右下角
    <mce:scripttype="text/javascript"><!--window.onresize=window.onscroll=window.onload=function(){varwin_w=document.documentElement.clientWidth;//窗口宽varspace_w=0;//左空白宽if(win_w>1000){//窗口大于ma......
  • ie6 ie 8 ff 总在页脚右下角的绝对定位top div
    top.jsfunctionsetH(){varmain_div_w=1010;vardiv_w=$e('top_t').offsetWidth;vardiv_h=$e('top_t').offsetHeight;//下面二行必须定义docw3c标准varwin_w=document.documentElement.clientWidth;varwi......
  • cp复制软连接
    在Linux中,使用cp命令复制软链接时,会根据命令行参数的不同而产生不同的结果:如果使用cp-L命令,cp会复制软链接指向的文件,而不是软链接本身。这个选项强制cp遵循软链接指向的路径,而不是复制软链接。如果使用cp-P命令,cp会复制软链接本身,而不是软链接指向的文件。这个选项使cp复制......
  • 在Amazon SageMaker平台上使用Docker部署Lambda函数
    目录1相关工具2准备工作3构建镜像4配置ECR并推送镜像5使用镜像创建Lambda函数6参考信息1相关工具AWSCLIAWSCommandLineInterface(AWSCLI)是一个命令行工具,我们可以用它在终端中与AWS服务进行交互文档:什么是AWSCommandLineInterface?-AWSCommandLineI......
  • 证明 一个 和 三角函数 有关 的 函数 单调递减
    吧主 @黎合胜  只会出物理题,  数学题还得我来,  嘿嘿 。 数学吧  《三角函数问题》     https://tieba.baidu.com/p/8384790600   。  ......
  • 阅读txt程序
    <html><head><HTA:APPLICATIONID="oHTA"APPLICATIONNAME="myApp"WINDOWSTATE=""MAXIMIZEBUTTON="no"border="thin"borderStyle="static"><metahttp-e......
  • C语言复习
    环境配置(Windows、Linux、Mac)https://fishc.com.cn/forum.php?mod=forumdisplay&fid=329&filter=typeid&typeid=571java与C语言的对比linux运行代码转义字符define把所有出现的标识符全部转换为常量写法:#define标识符常量例如#defineURL"www.baidu.com"#defineD......
  • 【教程分享】一键部署Redis,轻松搞定Docker安装和配置!
    1下载下载6.2.7版本:[root@service-monitoring~]#dockerpullredis:6.2.76.2.7:Pullingfromlibrary/redis025c56f98b67:Pullcomplete060e65aed679:Pullcompleteb95291e865b7:Pullcompletee3023c0b11d1:Pullcomplete143500497a02:Pullcompletec38298c......