I had a problem with my auto-fill input form, with PHP MySQL and jQuery of course. So I have the select option form and some 'disabled' textboxes. And I want when I select the one of the option, the textboxes is auto-fill with value from the database
So there is my whole code :
PHP (Database connection) - I put it above my <html> code
<?php
$host = 'localhost';
$user = 'root';
$pass = '';
$db = 'db_mydatabase';
mysql_connect($host, $user, $pass);
mysql_select_db($db);
$user = '';
$query = mysql_query("SELECT * FROM tb_payment") or die (mysql_error());
?>
HTML
<select name="student" class="input-data">
<option value="">-- SELECT STUDENT --</option>
<!-- Do loop data from database -->
<?php while ($row = mysql_fetch_object($query)): ?>
<option value="<?php echo $row->id_user ?>">
<?php echo $row->name ?>
</option>
<?php endwhile; ?>
</select>
<br />
<table border=1>
<tr>
<th>ID</th>
<td><input type="text" class="output-id" disabled /></td>
</tr>
<tr>
<th>Name</th>
<td><input type="text" class="output-name" disabled /></td>
</tr>
<tr>
<th>Total Payment</th>
<td><input type="text" class="output-total" disabled /></td>
</tr>
</table>
jQuery :
$(document).ready(function(){
$(".input-data").on("change", function(){
<?php $id_user = "$(this).val()"; ?>
<?php $data = mysql_query("SELECT * FROM tb_payment WHERE id_user = '$id_user'") or die (mysql_error()); ?>
<?php while($row = mysql_fetch_object($data)): ?>
$(".output-id").val(<?php $row->id_user ?>);
$(".output-name").val(<?php $row->name ?>);
$(".output-total").val(<?php $row->total ?>);
<?php endwhile; ?>
});
});
But when i try to select the option, the values are wouldn't appear. Can someone help me?
<in the 4th line of the jQuery part?while (row - mysql_fetch_object($query)):..$(document).ready(function(){ $(".input-data").on("change", function(){}); });