为什么我的留言箱没有运作?

时间:2014-05-12 01:48:26

标签: javascript php

我必须做一个有添加进程和编辑过程的系统。在这些过程中,我已经对消息框进行了编码,但是当我尝试它时,我发现消息框不起作用。我想当用户没有完成填写他们的信息时,已经点击提交按钮消息框出来。

有人可以帮我解决这个问题吗?这是代码:

<?php
include("authenticationStaff.php");
include ("dbase.php");  

        $query= "SELECT * FROM staff WHERE staff_name ='".$_SESSION['SESS_STAFF_NAME']."'";
        $result = mysql_query($query);


        $row = mysql_fetch_array($result);
        $id = $row["id"];
        $staff_id=$row["staff_id"];
        @mysql_free_result($result);

        error_reporting(E_ALL);
        ini_set('display_errors', 1);
?>
<html>
<head>
<script>

function Validate()
{
    if (document.addStaff.project_name.value == '') 
    {
       alert('Please Insert Project Name!');
       document.addStaff.project_name.focus();
       return false;
    }
    if (document.addStaff.project_id.value == '') 
    {
       alert('Please Insert Project ID !');
       document.addStaff.project_id.focus();
       return false;
    }
    if (document.addStaff.location.value == '') 
    {
       alert('Please Insert Location!');
       document.addStaff.location.focus();
       return false;
    }
    if (document.addStaff.cost.value == '') 
    {
       alert('Please Insert Cost!');
       document.addStaff.cost.focus();
       return false;
    }
    if (document.addStaff.pic.value == '') 
    {
       alert('Please Insert Person In Charge!');
       document.addStaff..pic.focus();
       return false;
    }
    if (document.addStaff.detail.value == '') 
    {
       alert('Please Insert Detail about the Project!');
       document.addStaff.detail.focus();
       return false;
    }
}
</script>
</head>
<body>

<table width="869" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
       <td width="645" height="50" align="left" valign="middle"><strong>Welcome ,&nbsp; You log in as &nbsp; &nbsp;<?php echo $_SESSION['SESS_STAFF_NAME'];?> </strong></td>
      <td width="224" align="right" valign="middle"><strong><a href="logout.html" title="Logout">Log Out</a></strong></td>
   </tr>
   </table>
   <?php
   $idURL = $_GET['id'];
   $query ="SELECT *
    FROM staff s
    JOIN inter1 i
    ON (s.staff_name=i.staff_name)";

$result = mysql_query($query, $conn) or die("Could not execute query");
$row = mysql_fetch_array($result, MYSQL_BOTH); // using numeric index or array index

    $staff_id = $row['staff_id'];
    $project_name = $row['project_name'];
    $location = $row['location'];
    $detail = $row['detail'];
    $pic = $row['pic'];
    $staff_name = $row['staff_name'];
    $project_id = $row['project_id'];


    @mysql_free_result ($result);
?>
   <center>
  <form action="addStaff_process.php?id=<?php echo $idURL; ?>" method="post" enctype="multipart/form-data" name="add_process" id="add_process" onsubmit="return Validate()" >
  <table border="1" width="70%" cellspacing="1" cellpadding="6" >
  <tr align="center" bgcolor="">
      <td   align="left"  style="padding:10px 10px 10px 10px;" >STAFF NAME:</td>
      <td  align="left"  style="padding:10px 10px 10px 10px;" ><textarea name="staff_name" cols="50" rows="2" id="staff_name"><?php echo $_SESSION['SESS_STAFF_NAME'];?></textarea></td>
    </tr>
    <tr align="center" bgcolor="">
      <td   align="left"  style="padding:10px 10px 10px 10px;" >STAFF ID:</td>
      <td  align="left"  style="padding:10px 10px 10px 10px;" ><textarea name="staff_id" cols="50" rows="2" id="staff_id"><?php echo $idURL; ?></textarea></td>
    </tr>
  <tr align="center" bgcolor="">
      <td   align="left"  style="padding:10px 10px 10px 10px;" >PROJECT ID:</td>
      <td  align="left"  style="padding:10px 10px 10px 10px;" ><textarea name="project_id" cols="50" rows="2" id="project_id"></textarea></td>
    </tr>
    <tr align="center" bgcolor="">
      <td   align="left"  style="padding:10px 10px 10px 10px;" >PROJECT NAME :</td>
      <td  align="left"  style="padding:10px 10px 10px 10px;" ><textarea name="project_name" cols="50" rows="2" id="project_name"></textarea></td>
    </tr>
    <tr align="center" bgcolor="">
      <td   align="left"  style="padding:10px 10px 10px 10px;" >LOCATION :</td>
      <td  align="left"  style="padding:10px 10px 10px 10px;" ><textarea name="location" cols="50" rows="2" id="location"></textarea></td>
    </tr>
    <tr align="center" bgcolor="">
      <td   align="left"  style="padding:10px 10px 10px 10px;" > COST :</td>
      <td  align="left"  style="padding:10px 10px 10px 10px;" ><textarea name="cost" cols="50" rows="2" id="cost"></textarea></td>
    </tr>
    <tr align="center" bgcolor="" >
      <td   align="left"  style="padding:10px 10px 10px 10px;" >PERSON IN CHARGE :</td>
      <td  align="left"  style="padding:10px 10px 10px 10px;" ><textarea name="pic" cols="50" rows="3" id="pic"></textarea></td>
    </tr>
    <tr>
      <td   align="left"  style="padding:10px 10px 10px 10px;">DETAIL ABOUT THE PROJECT:</td>
      <td  align="left"  style="padding:10px 10px 10px 10px;" ><textarea name="detail" cols="50" rows="4" id="detail"></textarea></td>
    </tr>
        </table>
        <p>&nbsp;</p>
        <p>
          <input class="form-submit" type="submit" name="submit" value="SUBMIT" onclick="return Validate()"/>
          <input type = "reset" value = "RESET" />
        </p>
  </form>
</center>

</body>
</html>

1 个答案:

答案 0 :(得分:0)

addStaff不是document对象的属性或方法。因此,您的条件测试每次都会失败,并且if语句中的所有代码都不会运行。

我相信你正在寻找以下内容:

if (document.getElementById("project_name").value == "") {
    //Your error handling code...
}