js动态增加表单以及服务器如何接收参数

js动态增加表单页面:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
#main {
height: 650px;
width: 800px;
margin-top: 5px;
margin-right: auto;
margin-left: auto;
}
#main strong {
letter-spacing: 2px;
font-size: 18px;
}
#main strong a {
text-decoration: none;
}
#main #form1 table tr td {
line-height: 25px;
}
#main #form1 table tr th {
height: 25px;
}
#main #form1 table tr td #button {
width: 50px;
}
#main #form1 table tr td #button2 {
width: 50px;
}
.td{
background-color: #FFE;
height: 30px;
}
.tds{
background-color: #CCC;
height: 30px;
}
#main #form1 table tr .td #textfield2 {
width: 125px;
}
#main #form1 table tr .td #textfield3 {
width: 125px;
}
#main #form1 table tr .td #textfield4 {
width: 125px;
}
#main #form1 table tr .td #textfield5 {
width: 125px;
}
</style>
<SCRIPT LANGUAGE="JavaScript">
var i=0
function Add1()
{
 var temp=document.getElementById("add")
 temp.insertRow(temp.rows.length);
 temp.rows.item(temp.rows.length -1).insertCell(0);
 var xx=temp.rows.length -1 ;//-1
 var sHTML
 sHTML='<TABLE border=\"1\" style=\"border-collapse: collapse\" bordercolor=\"#111111\"width=\"100%\">' +
       '<TR>' +
       '<TD align=\"left\" width="25%"><SELECT NAME=\"\">'+
       '<option value=\"0\">&nbsp;-------------------&nbsp;</option>'+
  '<option value=\"1\">&nbsp;海马高度&nbsp;</option>' +
       '<option value=\"2\">&nbsp;脉络膜裂宽度&nbsp;</option>' +
   '<option value=\"3\">&nbsp;内嗅皮层厚度&nbsp;</option>' +
       '<option value=\"4\">&nbsp;颞叶干宽度&nbsp;</option>' +
   '<option value=\"5\">&nbsp;侧裂池宽度&nbsp;</option>' +
       '<option value=\"6\">&nbsp;海马total NAA/CR&nbsp;</option>' +
   '<option value=\"7\">&nbsp;海马total MI/CR&nbsp;</option>' +
       '<option value=\"8\">&nbsp;头NAA/CR&nbsp;</option>' +
   '<option value=\"9\">&nbsp;头MI/CR&nbsp;</option>' +
       '<option value=\"10\">&nbsp;体NAA/CR&nbsp;</option>' +
   '<option value=\"11\">&nbsp;体MI/CR&nbsp;</option>' +
       '<option value=\"12\">&nbsp;尾NAA/CR&nbsp;</option>' +
   '<option value=\"13\">&nbsp;尾MI/CR&nbsp;</option>' +
       '<option value=\"14\">&nbsp;杏仁核NAA/CR&nbsp;</option>' +
   '<option value=\"15\">&nbsp;杏仁核MI/CR&nbsp;</option>' +
       '<option value=\"16\">&nbsp;扣带回NAA/CR&nbsp;</option>' +
  '<option value=\"17\">&nbsp;扣带回MI/CR&nbsp;</option>' +
       '</SELECT>' +
       '</TD>' +
       '<TD align=\"left\" width="65%">&nbsp;左侧:&nbsp;<input type=\"text\" name=\"\">&nbsp;&nbsp;右侧:&nbsp;&nbsp;<input type=\"text\" name=\"\"></TD>' +
       '<TD align=\"center\" width="10%"><input type=\"button\" value=\" 删除 \" οnclick=\"Delete(this);\"></TD>'+
       '</TR>' +
       '</TABLE>';
 temp.rows.item(temp.rows.length-1).cells.item(0).innerHTML=sHTML;
 temp.rows.item(temp.rows.length-1).cells.item(0).children.item(0).rows.item(0).cells.item(2).children.item(0).text=xx;
 temp.rows.item(temp.rows.length-1).cells.item(0).children.item(0).rows.item(0).cells.item(0).children.item(0).name="seeo"+xx;
 temp.rows.item(temp.rows.length-1).cells.item(0).children.item(0).rows.item(0).cells.item(1).children.item(0).name="seeo"+xx+"L";
 temp.rows.item(temp.rows.length-1).cells.item(0).children.item(0).rows.item(0).cells.item(1).children.item(1).name="seeo"+xx+"R";
}
function Add2()
{
 var temp=document.getElementById("add1")
 temp.insertRow(temp.rows.length);
 temp.rows.item(temp.rows.length -1).insertCell(0);
 var xx=temp.rows.length -1 ;//-1
 var sHTML
 sHTML='<TABLE border=\"1\" style=\"border-collapse: collapse\" bordercolor=\"#111111\"width=\"100%\">' +
       '<TR>' +
       '<TD align=\"left\" width="25%" ><input type=\"text\" name=\"\"></TD>' +
       '<TD align=\"left\" width="65%">&nbsp;左侧:&nbsp;<input type=\"text\" name=\"\">&nbsp;&nbsp;右侧:&nbsp;&nbsp;<input type=\"text\" name=\"\"></TD>' +
       '<TD align=\"center\" width="10%"><input type=\"button\" value=\" 删除 \" οnclick=\"Delete2(this);\"></TD>'+
       '</TR>' +
       '</TABLE>';
 temp.rows.item(temp.rows.length-1).cells.item(0).innerHTML=sHTML;
 temp.rows.item(temp.rows.length-1).cells.item(0).children.item(0).rows.item(0).cells.item(2).children.item(0).text=xx;
 temp.rows.item(temp.rows.length-1).cells.item(0).children.item(0).rows.item(0).cells.item(0).children.item(0).name="seei"+xx;
 temp.rows.item(temp.rows.length-1).cells.item(0).children.item(0).rows.item(0).cells.item(1).children.item(0).name="seei"+xx+"L";
 temp.rows.item(temp.rows.length-1).cells.item(0).children.item(0).rows.item(0).cells.item(1).children.item(1).name="seei"+xx+"R";
}
function Delete(x)

 var temp=document.getElementById("add")
 temp.deleteRow(x.text.valueOf())
 for (var j=0;j<temp.rows.length;j++) {
 temp.rows.item(j).cells.item(0).children.item(0).rows.item(0).cells.item(2).children.item(0).text=j;
  temp.rows.item(j).cells.item(0).children.item(0).rows.item(0).cells.item(0).children.item(0).name="seeo"+j;
  temp.rows.item(j).cells.item(0).children.item(0).rows.item(0).cells.item(1).children.item(0).name="seeo"+j+"L";
 temp.rows.item(j).cells.item(0).children.item(0).rows.item(0).cells.item(1).children.item(1).name="seeo"+j+"R";
}}
function Delete2(x)

 var temp=document.getElementById("add1")
 temp.deleteRow(x.text.valueOf())
 for (var j=0;j<temp.rows.length;j++) {
 temp.rows.item(j).cells.item(0).children.item(0).rows.item(0).cells.item(2).children.item(0).text=j;
  temp.rows.item(j).cells.item(0).children.item(0).rows.item(0).cells.item(0).children.item(0).name="seei"+j;
  temp.rows.item(j).cells.item(0).children.item(0).rows.item(0).cells.item(1).children.item(0).name="seei"+j+"L";
 temp.rows.item(j).cells.item(0).children.item(0).rows.item(0).cells.item(1).children.item(1).name="seei"+j+"R";
}}
</SCRIPT>
</head>
<body>
<div id="main">
<br>
  <strong><a href="<?php echo $this->baseUrl?>/<?php echo $this->show?>">病人信息</a>|<a href="<?php echo $this->baseUrl?>/<?php echo $this->search?>">查找病人</a>|<a href="<?php echo $this->baseUrl?>/<?php echo $this->add?>">添加病人 </a>|<a href="<?php echo $this->baseUrl?>/<?php echo $this->medreport?>">病历检索 </a>
  </strong>
<form id="form1" name="form1" method="post" action="<?php echo $this->searchform?>">
    <table width="100%" border="1" cellspacing="0" cellpadding="0">
      <tr>
        <th colspan="2" align="left" scope="col">病人信息:</th>
      </tr>
      <tr>
        <td width="18%" class="td">姓名:</td>
        <td width="82%" class="td"><label for="textfield"></label>
        <input type="text" name="name" id="textfield" /></td>
      </tr>
      <tr>
        <td class="td">性别:</td>
        <td class="td"><input type="radio" name="sex" id="radio" value="男" />
        <label for="radio"> 男 &nbsp;&nbsp;
          <input type="radio" name="sex" id="radio2" value="女" />
        女</label></td>
      </tr>
      <tr>
        <td class="td">年龄:</td>
        <td class="td"><label for="select"></label>
          <select name="age" id="select">
          <option value=0 selected="selected">--------------</option>
           <option value=1 >0-5</option>
           <option value=2 >6-15</option>
           <option value=3 >16-30</option>
           <option value=4 >31-60</option>
           <option value=5 >61-</option>
        </select></td>
      </tr>
      <tr>
        <th colspan="2" align="left">检查信息:&nbsp;&nbsp;<INPUT TYPE="button" value="增添(选择项)" οnclick="Add1()">
&nbsp;&nbsp;<INPUT TYPE="button" value="增添(填写项)" οnclick="Add2()">
<span style="color: #F00">[注:建议使用“增添(选择项)”,搜索更快,更准确]</span></th>
      </tr>
      <tr>
      <td colspan="2" align="center" class="td">
      <table align=center border=0 width="100%" height="100%">
<tr>
       <td width="100%" height="220" align="center">
           <div style=" OVERFLOW: auto;BORDER-RIGHT: 1px solid; BORDER-TOP: 1px solid; BORDER-LEFT: 1px solid; BORDER-BOTTOM: 1px solid; WIDTH: 100%; HEIGHT: 100%">
                <table width="100%" id="add">
                </table>
<table width="100%" id="add1">
</table>
         </div>
    </td>
</tr>
</table>
      <td>
      </tr>
         <tr>
        <th colspan="2" align="left" scope="col" >诊断结果:</th>
      </tr>
      <tr>
      <td colspan="2" align="left" class="td">
        &nbsp;<input type="text" name="result1" id="textfield2" />
        <select name="result12" id="select2">
<option value="and">&nbsp;and&nbsp;</option>
<option value="or">&nbsp;or&nbsp;</option>
        </select>
        <input type="text" name="result2" id="textfield3" />
        <select name="result23" id="select3">
<option value="and">&nbsp;and&nbsp;</option>
<option value="or">&nbsp;or&nbsp;</option>
        </select>
        <input type="text" name="result3" id="textfield4" />
        <select name="result34" id="select4">
<option value="and">&nbsp;and&nbsp;</option>
<option value="or">&nbsp;or&nbsp;</option>
        </select>
        <input type="text" name="result4" id="textfield5" /></td>
      </tr>
      <tr>
        <td colspan="2" align="left"><input type="hidden" name="medreport_search" value="search">
        <input type="submit" name="button" id="button" value="提交" />&nbsp;&nbsp;<input type="reset" name="button2" id="button2" value="重置" />
        </td></tr>
    </table>
  </form>
</div>
</body>
</html>

后台接收数据:

if(isset($_POST["medreport_search"])&&($_POST["medreport_search"]=="search"))
        {  
        session_unset();
        foreach ($_POST as $key=>$value)
        $_SESSION[$key]=$value;       
        }   


如果将session_unset();改为unset($_SESSION),则,页面刷新后,$_SESSION的各项值都被删除,这是为什么?刷新页面的时候,if条件块明明不能执行的。


另外,我们可以这样取出$_SESSION里的值。

如$i=1;

$_SESSION["seeo".$i]

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值