0

$row1 is the course title in the db table, $row[2] or $stu_type is the study type(under or postgraduate). Now, I am trying to make the selected value display in a text field. So since the values are being retrieved, that's fine. So say i select course1 (undergraduate) from the option, the value of $stu_type needs to:

  1. display in the textfield,
  2. change whenever i change the option value

This is the form image

enter image description here

i have gone through this link display select option from database when select option change but this isn't what i want to do

$sql = "SELECT * FROM tbl_courses";
$bam = mysqli_query($con, $sql);    
<select style="text-transform: uppercase;" name="title" id="title" class="form-control">
<?php while ($row1 = mysqli_fetch_array($bam)):;?>                                        
<?php
$stu_type = '';
if ($row1[2] == 'undergraduate') {
$stu_type = 'UnderGraduate';
}
else if ($row1[2] == 'postgraduate') {
$stu_type = 'PostGraduate';
}
?>
<script>
jQuery(document).ready(function($){
$('#title').change(function(){
$('#stu_type').val($(this).find(':selected').attr('data'));
});
});
</script>
<option value="<?php echo $row1[0]; ?>"><?php echo $row1[1]; ?> - <?php echo $stu_type;?></option>
<?php endwhile; ?>
</select>
<input type="text" name="stu_type" id="stu_type" value="<?=$_POST['title']?>">
mplungjan
  • 169,008
  • 28
  • 173
  • 236

0 Answers0