简体   繁体   中英

Why isn't my message box functioning?

I have to do 1 system that have add process and edit process. In these process I already put coding of message box but when I try it, I found that the message box does not work. I want when user does not finish fill their information and already click submit button the message box come out.

Can someone help me to fix this problem? Here is the code:

<?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 is a not a property or method of the document object. Therefore, your conditional tests are going to fail every time and none of the code in your if statements will run.

I believe you are looking for something along the lines of:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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