I had here a ajax function for posting data in pr field. What I need to do is post all the value base on pr# in my database. How I can post the other data in different textboxes using ajax? Below is my database structure and image and codes. Any help will be appreciate.
Pr Database Details Structure
Pr # | Supplier | Receipt # | Receiver |
--------------------------------------------
321-B | Villman | 312312331 | John |
556-B | Dockers | 903232317 | William |
Here's my Code
index.php
<select id="pr">
<?php ... ?>
</select>
<input id="pr_num">
<input id="supplier">
<input id="receipt">
<input id="receiver">
<script type="text/javascript">
$(document).ready(function()
{
$('input[id="pr"]').change(function()
{
var prjt_code = $("#pr").val();
$.ajax({
type: "POST",
url: "ajax.php",
data :"pr_code="+pr_code,
dataType:'html',
type:'POST',
success:function(data){
//alert(data);
$('#pr_num').val(data);
}
});
return false;
});
});
</script>
Ajax.php
<?php
if(isset($_POST['pr_code'])) {
$pr_code= $_POST['pr_code'];
$sql = $mysqli->query("SELECT * FROM pr_table WHERE pr='$pr_code'");
while($row = $sql->fetch_assoc())
{
$code = $row['pr'];
}
echo $code;
}
?>