繁体   English   中英

为什么我的消息框不起作用?

[英]Why isn't my message box functioning?

我必须做1系统具有添加过程和编辑过程。 在这些过程中,我已经对消息框进行了编码,但是当我尝试编码时,发现消息框不起作用。 我想在用户未完成填写信息并且已经单击“提交”按钮时出现消息框。

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

<?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>

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

我相信您正在寻找以下方面的东西:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM