Is it possible to call a function when a different option value is select from a select box? the select box consists of 'approved' 'pending' and 'dissapproved'. I have a form which will automatically flag the submission as 'pending' when entered in the database.
When changed by an admin from 'pending' to 'approved' or 'disapproved' this will run a SQL query to update the information in the table. What table structure would be best suited to this? and how can I ensure that when the option value is changed a CSS class is applied to the affected row of table cells. Which will remain the same unless changed. I have tried with jQuery however I do not feel it meets my requirements
Code:
<?php
$result = mysql_query("SELECT * FROM Orders")
or die (mysql_error());
?>
<form method ="post" action="sendemail.php">
<table style ="background-color:#ffffff;">
<tr>
<th>Order Number</th>
<th>Order Date</th>
<th>Ordered By</th>
<th>Supplier</th>
<th>Total Price</th>
<th>Requested By</th>
<th>Status</th>
</tr>
<?php
while ($row = mysql_fetch_assoc($result))
{
echo '<tr>';
echo '<td><input type="text" name="order_n`enter code here`o[]" value="' . $row['Orderno'] . '"/> </td>';
echo '<td><input type="text" name="order_date[]" value="' . $row['Orderdate'] . '"/></td>';
echo '<td><input type="text" name="order_ordered_by[]" value="' . $row['Orderedby'] . '"/></td>';
echo '<td><input type="text" name="order_supplier[]" value="' . $row['Supplier'] . '"/></td>';
echo '<td><input type="text" name="order_total_price[]" value="' . $row['totalprice'] . '"/></td>';
echo '<td><input type="text" name="order_requested_by[]" value="' . $row['requestedby'] . '"/></td>';
echo '<td>';
echo '<select name="order_status[]">';
echo '<option></option>';
echo '<option>Approved</option>';
echo '<option>Pending</option>';
echo '<option>Dissaproved</option>';
echo '</select>';
echo '</td>';
echo '</tr>';
}
?>
Current jQuery to change table row colour, however I would like to add a CSS class to each option value and when the status is changed, this is reflected in the database, applying the correct class.
<script type="text/javascript">
$(document).ready(function() {
var color = ['none', '#DEF3CA', '#EECFA1', '#FFCCCC'];
$('table').on('change','select', function() {
$(this).parents('tr').css('background', color[$(':selected', this).index()]);
});
});
</script>
Table CSS:
<style type = "text/css">
table,td {
border:1px solid #999;
font-family: Tahoma,Arial,verdana;
font-size: 12px;
width:auto;
font-weight: none;
line-height: 1.4em;
font-style: normal;
border-collapse:separate;
}
td {
width:250px;
padding:15px;
color:#000;
border:1px solid;
border-bottom:1px solid;
}
</style>
SendEmail script to email each person based on 'Requestedby'
<?php
if(isset($_POST['order_requested_by']))
{
$row_count = count($_POST['order_requested_by']);
for($i=0; $i<$row_count; $i++)
{
$to = $_POST['order_requested_by'][$i];
$subject = "Order Status";
$message = "Your order number: " . $_POST['order_no'][$i] ." ". "is" ." ". $_POST['order_status'][$i];
$orderdate = "Order date: " . $_POST['order_date'][$i];
$from = "no-reply@.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$orderdate,$headers);
echo "Mail Sent.";
}
?>
Send the selection value to another page via a variable and then