Hello all, looking for some help here as I seem to be fairly stuck... this yields no results at all and I give up, I need help!
The user should be able to select an employee from a select field, and based on their selected we should be able to grab the start time and end time of that empoyee, which resides on the database.
My form:
<form action=".php" name="absence" id="absence" method="post">
Employee:
<select name="empid" class="clockinputs" required>
<option value=""></option>
<option value='20'>Bob Jones</option>
<option value='13'>Bob Phones</option>
<option value='93'>Bob Lomes</option>
<option value='30'>Bob Somes</option>
<option value='107'>Bob Pomes</option>
<option value='74'>Bob Womes</option>
</select>
Shift Start: <input type="text" name="startshift" id="startshift" class="clockinputs" data-inputmask="'mask': '99:99:99'" required>
Shift End: <input type="text" name="endshift" id="endshift" class="clockinputs" data-inputmask="'mask': '99:99:99'" required>
<input type="hidden" name="eid" value="<?php echo $row{'EID'}; ?>">
<input type="submit" value="Save">
</form>
Javascript:
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery('#empid').live('change', function(event) {
$.ajax({
url : 'absence-get.php',
type : 'POST',
dataType: 'json',
data : $('#absence').serialize(),
success: function( data ) {
for(var id in data) {
$(id).val( data[id] );
}
}
});
});
});
</script>
And absence-get.php:
<?php
$e = $_POST['empid'];
$result = mysql_query("SELECT * FROM employees WHERE EID='$e' ");
$row = mysql_fetch_array($result, MYSQL_ASSOC)
$startshift = $row{'startshift'};
$endshift = $row{'endshift'};
$arr = array( 'input#startshift' => $startshift , 'input#endshift' => $endshift );
echo json_encode( $arr );
?>
Anyone spot anything? Thank you!