Link to home
Create AccountLog in
Avatar of memberfromuk
memberfromuk

asked on

Textbox to appear when dropdown menu selection = 'Reject'

I have a simple system that deals with internal orders. Once an order is made by a member of staff a notification is sent to the manager who can then complete the order or reject it.
What I would like is when the manager clicks on 'Reject' from the drop down menu a text box appears that allows him to enter his reasons for rejection. I have a field in my database already called 'comments' that i want it to be saved too.
It would also be handy if the manager changes his mind and selects complete instead the textbox then disappears but this is not a major issue.
I have attached the code that has the drop down menu in, the query is on a seperate page but only contains a simple insert query.
Thank you in advance.
<?php
	session_start();
	if (isset($_SESSION['username']) == false){
		header("Location: login.php");
		exit();
	}
	require "connect.php";
	
	$orderID = $_GET['orderID'];
	$query = "SELECT * FROM orders o, productorder p WHERE o.orderID = p.orderID AND p.status = 'Awaiting Approval' AND o.orderID = ".$orderID;
 
	$result = mysql_query($query, $connection) or die ("Unable to perform query $query");
	
	$row= mysql_fetch_array($result);
	
	$query3 = "SELECT * FROM orders WHERE orderID = ".$orderID;
	$result3 = mysql_query($query3, $connection) or die ("Unable to perform query $query3");
	
	$row3= mysql_fetch_array($result3);
 
?>
<!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=iso-8859-1" />
<title>Order Approval</title>
<link rel="stylesheet" type="text/css"
href="mystylelogin.css" />
</head>
 
<body>
<?php
switch ($_SESSION['type']) 
	{
		case 'user':
    	include ("header.php");
		include ("StationaryHeader.php");
    	break;
  
		case 'admin':
		include ("headerAdminMain.php");
		include ("StationaryHeader.php");
		break;
		
		case 'manager':
		include ("header.php");
		include ("StationaryHeaderManager.php");
		break;
	}
?>
 
<div id="header">Order Approval</div>
 
 
<div id="OrdersBasketTable">
<table border="0" width="100%">
<hr />
	<tr>
		<th width="100">Order Number</th>
	</tr>
			<tr><td align="center"><h2><strong><?php echo $row['orderID']?></strong></h2></td>
			<td>
			<table border="0"width="100%">
			<tr>
				<th width="30%" align="left">Product</th>
				<th width="10%" align="left">Price</th>
				<th width="10%" align="left">Quantity</th>
				<th width="14%" align="left">Date</th>
				<th width="25%" align="left">User</th>
				<th width="13%" align="left">Total</th>
			</tr>
			<tr>
 
	<?php
	$query2 = "SELECT * FROM orders o, productorder e, product p WHERE o.orderID = e.orderID AND p.URN = e.URN AND e.status = 'Awaiting Approval' AND o.orderID = '".$row['orderID']."'";
	$result2 = mysql_query ($query2, $connection) or die ("Unable to perform query<br>$query2");
 
				while($row2=mysql_fetch_array($result2))
				{ ?>
	  		  <tr>
						<td><?php echo $row2['productName']?></td>
						<td>&pound;<?php echo $row2['price']?></td>
						<td align="center"><?php echo $row2['quantity']?></td>
						<td><?php echo $row2['date']?></td>
						<td><?php echo $_SESSION['fName']?>&nbsp;<?php echo $_SESSION['sName']?></td>
 
						<?php $total = $row2['quantity'] * $row2['price']; ?>
						<td>£<?php echo $total ?></td>
						<?php $total2 = $total2 + $total ?>
	  		  </tr>
					<?php
				} ?>
				</td>
				</tr>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td><strong>Total</strong></td>
				<td>£<?php echo $total2 ?></td>
				<td></td>
	  </table>
</table>
	</td>
</table>
 
	<form action="OrderApprovalQuery.php" method="get">
	<table width ="100%" border="0">
		<tr>
		  <td>Status:</td>
		  <td><select name="status">
            <option>Awaiting Approval</option>
            <option>Complete</option>
            <option>Reject</option>
          </select></td>
		  <td>&nbsp;</td>
	  </tr>
		<tr>
		  <td><input name="orderID" type="hidden" value="<?php echo $row3['orderID']?>"  /></td>
		  <td>&nbsp;</td>
		  <td>&nbsp;</td>
	  </tr>
		<tr>
			<td width="20%">&nbsp;</td>
        	<td width="22%"><input name="Save" type="submit" value="Update" /></td>
        	<td width="58%">&nbsp;</td>
		</tr>
	</table>
	</form>
</div>
</body>
</html>

Open in new window

Avatar of hielo
hielo
Flag of Wallis and Futuna image

Here you go. In OrderApprovalQuery.php you will need to retrieve the comments as:
$comment = empty($_REQUEST['comments']) ? "" : $_REQUEST['comments'];
<?php
      session_start();
      if (isset($_SESSION['username']) == false){
            header("Location: login.php");
            exit();
      }
      require "connect.php";
      
      $orderID = $_GET['orderID'];
      $query = "SELECT * FROM orders o, productorder p WHERE o.orderID = p.orderID AND p.status = 'Awaiting Approval' AND o.orderID = ".$orderID;
 
      $result = mysql_query($query, $connection) or die ("Unable to perform query $query");
      
      $row= mysql_fetch_array($result);
      
      $query3 = "SELECT * FROM orders WHERE orderID = ".$orderID;
      $result3 = mysql_query($query3, $connection) or die ("Unable to perform query $query3");
      
      $row3= mysql_fetch_array($result3);
 
?>
<!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=iso-8859-1" />
<title>Order Approval</title>
<link rel="stylesheet" type="text/css"
href="mystylelogin.css" />
</head>
 
<body>
<?php
switch ($_SESSION['type']) 
      {
            case 'user':
          include ("header.php");
            include ("StationaryHeader.php");
          break;
  
            case 'admin':
            include ("headerAdminMain.php");
            include ("StationaryHeader.php");
            break;
            
            case 'manager':
            include ("header.php");
            include ("StationaryHeaderManager.php");
            break;
      }
?>
 
<div id="header">Order Approval</div>
 
 
<div id="OrdersBasketTable">
<table border="0" width="100%">
<hr />
      <tr>
            <th width="100">Order Number</th>
      </tr>
                  <tr><td align="center"><h2><strong><?php echo $row['orderID']?></strong></h2></td>
                  <td>
                  <table border="0"width="100%">
                  <tr>
                        <th width="30%" align="left">Product</th>
                        <th width="10%" align="left">Price</th>
                        <th width="10%" align="left">Quantity</th>
                        <th width="14%" align="left">Date</th>
                        <th width="25%" align="left">User</th>
                        <th width="13%" align="left">Total</th>
                  </tr>
                  <tr>
 
      <?php
      $query2 = "SELECT * FROM orders o, productorder e, product p WHERE o.orderID = e.orderID AND p.URN = e.URN AND e.status = 'Awaiting Approval' AND o.orderID = '".$row['orderID']."'";
      $result2 = mysql_query ($query2, $connection) or die ("Unable to perform query<br>$query2");
 
                        while($row2=mysql_fetch_array($result2))
                        { ?>
                      <tr>
                                    <td><?php echo $row2['productName']?></td>
                                    <td>&pound;<?php echo $row2['price']?></td>
                                    <td align="center"><?php echo $row2['quantity']?></td>
                                    <td><?php echo $row2['date']?></td>
                                    <td><?php echo $_SESSION['fName']?> <?php echo $_SESSION['sName']?></td>
 
                                    <?php $total = $row2['quantity'] * $row2['price']; ?>
                                    <td>?<?php echo $total ?></td>
                                    <?php $total2 = $total2 + $total ?>
                      </tr>
                              <?php
                        } ?>
                        </td>
                        </tr>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td><strong>Total</strong></td>
                        <td>?<?php echo $total2 ?></td>
                        <td></td>
        </table>
</table>
      </td>
</table>
 
      <form action="OrderApprovalQuery.php" method="get">
      <table width ="100%" border="0">
            <tr>
              <td>Status:</td>
              <td>
		    <script type="text/javascript">
		    function handleChoice(sel)
		    {
		    	var choice = sel.options[sel.options.selectedIndex].text;
			if("Reject"==choice)
			{
				document.getElementById("commentsField").style.display='';
			}
		    }
		    </script>
		    <select name="status" onchange="handleChoice(this)">
            <option>Awaiting Approval</option>
            <option>Complete</option>
            <option>Reject</option>
          </select><div id="commentsField" style="display:none"><textarea name="comments" rows="10" cols="80"></textarea></div></td>
              <td> </td>
        </tr>
            <tr>
              <td><input name="orderID" type="hidden" value="<?php echo $row3['orderID']?>"  /></td>
              <td> </td>
              <td> </td>
        </tr>
            <tr>
                  <td width="20%"> </td>
              <td width="22%"><input name="Save" type="submit" value="Update" /></td>
              <td width="58%"> </td>
            </tr>
      </table>
      </form>
</div>
</body>
</html>


Open in new window

Avatar of memberfromuk
memberfromuk

ASKER

Hi,

Yeah that is excellent. Does it take much more code to make it disappear if the drop down menu changes to complete?!
ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account