<tr>
<td>Credit Account No: </td>
<td><select name="debitacc">
<?php
$sql = "SELECT * FROM account";
$res = mysqli_query($conn, $sql);
$count = mysqli_num_rows($res);
if($count>0)
{
while($row=mysqli_fetch_assoc($res))
{
$code = $row['code'];
$id = $row['id'];
?>
<option value="<?php echo $id;?>"><?php echo $code; ?></option>
<?php
}
}
else
{
echo "<option value='0'>No Account.</option>";
}
?>
</select>
</td>
<td>Account Name: </td>
<td><input type="text" name="creditaccname" placeholder="Enter Your Account Name"></td>
</tr>
I have saved my an account in phpMyAdmin
id code name
1 1234 bank charge
2 9988 CIMB
How do I if select the code 1234
will automatic echo in <td> Acc
name of the code
2
Answers
Code concept sample: Generate HTML/JabaScript like the following
DISCLAIMER: There are JavaScript conformation concerns regarding inline JavaScript usage and proper HTML definition. You should follow them accordingly, I just wanted to help here with the concept.
It’s easy to store the code name value as a data-attribute in the option, and then reference it at the time of selection using a
change
event.