添加<form>?</form>后出现问题

时间:2010-04-19 23:12:31

标签: php javascript html forms

当我将<form>添加到我的网页时,我的所有javascript都停止了工作,当我把表单放在我的表开头时提交无法正常工作,我做错了什么。下面是我在其他浏览器上测试后的代码,它工作正常,但在Firefox上它没有

更新:检查firefox java错误控制台后,似乎Checking函数已定义

Update2:解决了我的错误是<script type="text/jscript">是错误的,这就是为什么在firefox上它没有工作,其余部分是,它必须是<script type="text/javascript">

<!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>Sabay Afrah.Inc | Contact Us</title>
<script src="js/clear.js" language="javascript" type="text/javascript"></script>
<script src="js/SpryValidationSelect.js" type="text/javascript"></script>
<script type="text/jscript">

function Checking(form){

if(empty(form.fname.value){

         alert("do nothing");

         }
}

</script>

<style type="text/css">
<!--
body {
    background-color: #000;
}
body,td,th {
    color: #FFF;
    font-size: 14px;
}
.address {
    font-family: "Comic Sans MS", cursive;
    font-weight: bold;
}
-->
</style>
<link href="theme/style.css" rel="stylesheet" type="text/css" />
<link href="theme/SpryValidationSelect.css" rel="stylesheet" type="text/css" />
</head>

<body>
<form  action="enterdb.php" method="post">
<table width="1000" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td align="center">&nbsp;</td>
  </tr>
  <tr>
    <td><table width="1006" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="4">&nbsp;</td>
        <td width="93" align="right">&nbsp;</td>
        <td width="4">&nbsp;</td>
        <td width="374" ><img src="images/logo.png" width="230" height="114" /></td>
        <td width="426" align="right" class="address">
        10 GlenLake parkway<br />
Suite 130, mailbox # 76<br />
Atlanta, GA 30328<br />
Phone #: + 678-222-3442<br />
Fax #: +678-222-3401<br />
Office hours: M-F 8:30 a.m. to 5:00 p.m.<br />
        </td>
        <td width="99">&nbsp;</td>
      </tr>
      <tr>
        <td colspan="5"><table width="600" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td>&nbsp;</td>
            <td class="title">&nbsp;</td>
          </tr>
          <tr>
            <td width="84"><br /></td>
            <td width="516" class="title">Contact Us</td>
          </tr>
        </table></td>
        <td>&nbsp;</td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td>

    <table width="883" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr class="table">
        <td width="27" rowspan="10" bgcolor="#330099" class="textable">&nbsp;</td>
        <td colspan="2" bgcolor="#330099" class="textable">&nbsp;</td>
        <td width="29" rowspan="8" bgcolor="#330099" class="textable">&nbsp;</td>
        <td colspan="3" class="textable">&nbsp;</td>
        </tr>
      <tr >
        <td width="139" height="31" bgcolor="#330099" class="textable">First Name:</td> <td>

         <input id="fname" name="fname" type="text" size="40" /> </td>
        <td width="150" class="textable">Last Name:</td>
        <td width="265" class="textable"><table width="200" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td ><table width="200" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td ><input id="lname" name="lname" type="text" size="40"  /></td>
              </tr>
            </table></td>
          </tr>
        </table></td>
        <td width="32" class="textable">&nbsp;</td>
      </tr>
      <tr>
        <td height="30" class="textable">Subject:</td> <td>
          <span id="spryselect1">
            <label>
              <select name="sub" id="sub">
              <option> Choose a Subject</option>
              <option> General Question</option>
              <option> MemberShip Area</option>
              <option> Others</option>

              </select>
            </label>
            <span class="selectRequiredMsg">Please select a Subject.</span></span>
        </td>
        <td colspan="3" class="textable">&nbsp;</td>
        </tr>
      <tr>
        <td height="33" class="textable">Company Name:</td> <td> <input id="cname" name="cname" type="text" size="40"   /></td>
        <td class="textable">Company Address:</td>
        <td class="textable"><table width="200" border="0" cellspacing="0" cellpadding="0">

          <tr>
           <td><input id="cadd" name="cadd" type="text" size="40" onclick=""  /></td>
          </tr>

        </table></td>

        <td class="textable">&nbsp;</td>
      </tr>
      <tr>
        <td height="31" class="textable">Phone Number:</td> <td><input id="phonen" name="phonen" type="text" size="40"  /> </td>
        <td colspan="3" rowspan="4" class="textable">&nbsp;</td>
        </tr>
      <tr>
        <td height="31" class="textable">Fax Number:</td><td> <input id="faxn" name="faxn" type="text" size="40" /></td>
        </tr>
      <tr>
        <td height="32" class="textable">Email Address:</td><td><input id="email" name="email" type="text" size="40" /></td>
        </tr>
      <tr>
        <td colspan="2" class="textable">&nbsp;</td>
        </tr>
      <tr>
        <td valign="top" class="textable">Additional Information:</td>
        <td colspan="5" class="textable"><table width="600" border="0" align="left" cellpadding="0" cellspacing="0">
          <tr>
            <td colspan="2" align="center">

            <textarea id="add" name="add" cols="70" rows="10" /></textarea>
            </td>
            </tr>
          <tr>
            <td align="center" class="textable">
              <input name="Submit" type="submit"  value="Submit" onclick="Checking()"/>
            </td>
            <td align="center" class="textable">

            <input type="reset"  value="Clear" />



            </td>
          </tr>
        </table></td>
        </tr>
      <tr>
        <td colspan="6" class="textable">&nbsp;</td>
        </tr>
    </table></td>
  </tr>
</table>
</form>
<script type="text/javascript">
<!--
var spryselect1 = new Spry.Widget.ValidationSelect("spryselect1");
//-->
</script>
</body>
</html>

3 个答案:

答案 0 :(得分:2)

您的函数想要接受表单元素,并且您的提交按钮不会向函数发送任何内容。我假设它没有提交,因为你的函数错误输出因此停止按钮就像它返回false一样。修复你的JavaScript,尝试使用Firebug来帮助你找到这些问题。

答案 1 :(得分:1)

尝试在表单标记中添加onsubmit:

<form  action="enterdb.php" method="post" enctype="application/x-www-form-urlencoded" onsubmit="return Checking(this);">

然后从提交按钮中删除onclick事件。

您需要将表单对象传递给Checking函数,因此this。此外,通常最好将处理程序放在表单标记中,因为当用户通过单击提交按钮或在表单中的其他位置按Enter键提交表单时,它将被调用。

根据webdestroya编辑。

答案 2 :(得分:0)

通常,建议您先注释掉clear.js和SpryValidationSelect.js,然后尝试通过添加逐个javascript文件来运行代码,以清楚地定义使用内联代码文本崩溃的文件。

还尝试为表单添加名称,并尝试这样:

function Checking(form){

  if(empty(window.myform.fname.value){

         alert("do nothing");

         }
  }

以一种调试方式,最好尝试不同的方法,有时你会发现不容易。

只是我的想法。 gudluck