一个页面里有两个form,第二个form里面有两个submit,怎么进行分别处理。下面我写的代码。
如果我myform不加action,想用script里定义的函数调用不了,点submit直接到了form1的action那里。怎么改?<?php 
//session_start();
include('include/dbconnect.php');?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>客房编辑修改</title>
<link rel="stylesheet" type="text/css" href="style.css">
<script   language="javascript"   type="text/javascript"> //控制action  
  function   SelSubmit1()   
  {   
  document.myform.action='main_index.php?lm=预定';   
  document.myform.submit();   
  }   
  function   SelSubmit2()   
  {   
  document.myform.action='test1.php';   
  document.myform.submit();   
  }  
</script>
<style type="text/css">
<!--
.STYLE1 {color: #FFFFFF}
.STYLE2 {font-size: 12px}
.STYLE4 {font-size: 13px}
.STYLE5 {font-family: "华文琥珀"; font-size: 20px;}
-->
</style>
</head>
<body bgcolor="#7791EA">
<table width="500" height="60" border="0" align="center" cellpadding="0" cellspacing="0">
     <tr>
    <td align="center" class="STYLE5">客房查询预定</td>
  </tr>
</table>
<table width="500" height="25" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td bgcolor="#2D5D2B">
    <table width="500" height="25" border="0" align="center" cellpadding="0" cellspacing="1">
      <form name="form1" method="post" action="main_index.php?lm=">
      <tr>
        <td bgcolor="#9ABADA"><div align="center">客房类型:
           <select name="style" size="1" id="style">
           <?php $query="select * from style";
            $result=mysql_query($query);
            if($result==true){
                while($myrow=mysql_fetch_array($result)){
        ?> <option><?php echo $myrow[stylename]; //$_SESSIONS["style"]=$myrow[stylename];?></option> 
            <?php  
   }
            }
            ?> 
        </select>&nbsp;<input type="submit" name="submit" value="查询" class="buttoncss"></div>
        </td>
      </tr>
      </form>
    </table>
    </td>
  </tr>
</table>
<table width="500" height="10" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td></td>
  </tr>
</table>
<?php
if($_POST[submit]!="")
{
?>
<table width="500" height="50" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td bgcolor="#256B25" valign="middle">
    <table width="500" height="50" border="0" align="center" cellpadding="0" cellspacing="1">
      <tr>
        <td width="100" height="25" bgcolor="#9ABADA"><div align="center" class="STYLE1">客房号码</div></td>
        <td width="120" bgcolor="#9ABADA"><div align="center" class="STYLE1">客房类型</div></td>
        <td width="100" bgcolor="#9ABADA"><div align="center" class="STYLE1">客房状态</div></td>
        <td width="90" bgcolor="#9ABADA"><div align="center" class="STYLE1">容纳人数</div></td>
        <td bgcolor="#9ABADA"><div></div></td> 
      </tr>
      <?php
      include('include/dbconnect.php');
      $style=$_POST[style];
      $sql=mysql_query("select * from roomlist where `style`='$style' AND `condition`='空闲'");     //ORDER BY roomnum desc  $sql = "select * from roomlist where `style` in (select `style` from roomlist where `style`=\'大包厢\')";
      $rs=mysql_fetch_array($sql);
      if($rs==false)
       {
      ?>
      <tr>
        <td height="25" colspan="5" bgcolor="#FFFFFF"><div align="center">没有查找到任何记录!</div></td>
      </tr>
    <?php
      }
      else
      { 
       do{
    ?>
      <tr>
      <form name="myform" action="main_index.php?lm=预定" method="post">   <!--显示查询结果-->
            <input type="hidden" name="<?php echo $rs[roomnum];?>" value="<?php echo $rs[roomnum];?>">
        <td height="25" bgcolor="#FFFFFF"><div align="center"><?php echo $rs[roomnum]; //$_SESSION["res_rnum"]=$rs[roomnum];?></div></td>   <!--<input type="text" readonly="readonly" value="<?php echo $rs[roomnum];?>" name="roomnum">-->
        <td height="25" bgcolor="#FFFFFF"><div align="center"><?php echo $rs[style];?></div></td>
        <td height="25" bgcolor="#FFFFFF"><div align="center"><?php echo $rs[condition];?></div></td>
        <td height="25" bgcolor="#FFFFFF"><div align="center"><?php echo $rs[capacities];?></div></td>
        <td height="25" bgcolor="#FFFFFF"><div align="center"><input type="submit" value="预订" name="Submit1" onclick="SelSubmit1()" />
            <input type="submit" name="Submit2" value="开房" onclick="SelSubmit2()" /></td>    
        </form>   
      </tr>
     <?php
       }while($rs=mysql_fetch_array($sql));
      }
     ?>
     </table> 
  </td>
  </tr>
</table>
<?php
 }
?>
<table height="100">
    <tr><td></td></tr>
</table>
</html>

解决方案 »

  1.   

    <input type='button' onclick='sub_1()'/>
    <input type='button' onclick='sub_2()'/>
    <script type='text/javascript'>
    function sub_1() {
     document.myform.action='http://www.baidu.com';
     document.myform.submit();
    }
    function sub_2() {
     document.myform.action='http://www.126.com';
     document.myform.submit()
    }
    </script>
      

  2.   

    myform的action是空白么? 我刚试了下 如果是空白的话 点下去没反应。。
      

  3.   

    试试这个。<script type='text/javascript'>
    function sub_1() {
     document.getElementById('myfrom')='http://www.baidu.com';
     document.getElementById('myfrom').submit();
    }
    function sub_2() {
     document.getElementById('myfrom')='http://www.google.com';
     document.getElementById('myfrom').submit();
    }
    </script><form id = 'myform'><input type='button' onclick='sub_1()'/>
    <input type='button' onclick='sub_2()'/></form>
      

  4.   


    貌似不能这样的,,不能 getbyid(form) 的。我试过,不能这样得到 form的。
      

  5.   

    form 都给了id 没????