combo box not working plz help me

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
siraj69
Forum Newbie
Posts: 1
Joined: Thu Dec 26, 2013 6:19 am

combo box not working plz help me

Post by siraj69 »

employess.php

<?php
$pdo = new PDO("mysql:host=localhost;dbname=erp1314;charset=utf8", "root", "");
?>
<html>
<head>
<link type="text/css" rel="stylesheet" href="style.css"/>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jq ... "></script>
</head>
<body>
<div id="content">
<h1 align="center">Add Training</h1>
<form action="employess.php" method="post">
<div>
<p>
Training ID:
<input type="text" name="Training_ID">
</p>
<p>
Employee ID:
<select id="JOB_NO">
<option value="">Select one</option>
<?php
$st = $pdo->prepare("SELECT JOB_NO FROM mm_client_loc_job");
$st->execute();
$rows = $st->fetchAll(PDO::FETCH_ASSOC);
foreach ($rows as $row) {
?><option value="<?php echo $row ['JOB_NO']; ?>"><?php echo $row ['JOB_NO']; ?></option><?php
}
?>
</select>
<p>
First name:
<input type="text" name="CLIENT_NAME" id="CLIENT_NAME">
</p>
<p>
Last name:
<input type="text" name="LOC_NAME" id="LOC_NAME">
</p>
<p>
Training required?
<select name="Training">
<option value="">Select...</option>
<option value="Customer Service">Customer Service</option>
<option value="Bailer">Bailer</option>
<option value="Reception">Reception</option>
<option value="Fish & meat counters">Fish & meat counters</option>
<option value="Cheese counters">Cheese counters</option>
</select>
</p>
<input type="submit">
</form>
</div>
<script type="text/javascript">
$(function() { // This code will be executed when DOM is ready
$('#JOB_NO').change(function() { // When the value for the Employee_ID element change, this will be triggered
var $self = $(this);
alert(JOB_NO); // We create an jQuery object with the select inside
$.post("getEmployeeData.php", { JOB_NO : $self.val()}, function(json)
{
if (json && json.status) {
$('#CLIENT_NAME').val(json.name);
$('#LOC_NAME').val(json.lastname);
}
})
});
})
</script>
</body>
</html>

getEmployeeData.php

<?php
$pdo = new PDO("mysql:host=localhost;dbname=erp1314;charset=utf8", "root", "");

//header("Content-Type:application/json; Charset=utf-8");

$st = $pdo->prepare("SELECT CLIENT_NAME, LOC_NAME FROM mm_client_loc_job WHERE JOB_NO = :job_No LIMIT 1");
$st->execute(array ('job_No' => $_POST['Job_No']));
$data = $st->fetch(PDO::FETCH_ASSOC);

echo json_encode(array ('status' => true, 'name' => $data ['CLIENT_NAME'], 'lastname' => $data ['LOC_NAME']));

?>
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: combo box not working plz help me

Post by Celauran »

Please wrap that in syntax tags so it's legible. Also, 'not working' is hardly descriptive. What is the expected behaviour? What is happening instead? What errors are you receiving? What have you already tried?
Post Reply