<script language="javascript" type="text/javascript">
function checkform(inputForm)
{
if (document.getElementById("id").value == "")
{
   alert("请填写编号");
  
   return false;
}}</script>
<form id="form1" name="form1" method="post" action="<?php echo $PHP_SELF?>">
  <table width="284" border="1">
    <tr>
      <td width="73">编号</td>
      <td width="195"><input type="text" name="id" id="id" value="" action="<?php echo $id?>" /></td>
    </tr>
    <tr>
  </table>
  <label><br />
  <input type="submit" name="Submit" value="提交" action="<?php echo $submit?>" />
  
  <br />
  <br />
  </label>
  <p>
    <label></label>
  </p>
</form>请问为什么不能触发判断呢?按了按钮后,没有任何反应。

解决方案 »

  1.   

    <input type="submit" name="Submit" value="提交" onclick="checkform('form1')" action="<?php echo $submit?>" /> 
    在input里面添加onclick时间。。你之前都没有调用那个函数,当然没反应
      

  2.   

    你这是要做什么呢?乱套,呵呵<script language="javascript" type="text/javascript">
    function checkform(f){
      if (document.getElementById("id").value == ""){  alert("请填写编号");  return false;}
      f.submit();
    }
    </script>
    <form id="form1" name="form1" method="post" action="" onsubmit="return checkform(this)">
      <table width="284" border="1">
      <tr>
      <td width="73">编号</td>
      <td width="195"><input type="text" name="id" id="id" /></td>
      </tr>
      <tr>
      </table>
      <label><br />
      <input type="submit" name="Submit" value="提交" />
      
      <br />
      <br />
      </label>
      <p>
      <label></label>
      </p>
    </form>
      

  3.   

    还是onsubmit比较好
    <form id="form1" name="form1" method="post" action="<?php echo $PHP_SELF?>" onsubmit="return checkform('form1')">
      

  4.   

    还有,你的<?php echo $PHP_SELF?>之类的PHP语句都应该加上分号:
    <?php echo $PHP_SELF;  ?>
      

  5.   

    在submit里面写action没意义,也不符合标准应该写在这里
    <form onSubmit="return checkform(this);" ...