I need to take UniversityID from the University selection to list institutes in this university for Institute Selection. I read it is easy with AJAX but I couldn't solve it. For now Institute selection show all the institutes.
Institute_1 and Institute_2 in University_1
Institute_3 in University_2
I want to show Institute_1 and Institute_2 in Institute selection if user chose University_1
or
Institute_3 if user chose University_2
How I can write AJAX part or is there any better way?
<label>University</label>
<select name="University" id="University">
<?php
$sql = "SELECT * FROM University";
$stmt = sqlsrv_query( $conn, $sql);
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true));
}
while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ) {
?>
<option value="<?php echo $row['UniversityID']; ?>"><?php echo $row['University_NAME']; ?></option>
<?php } ?>
</select>
<br>
<label>Institute</label>
<select name="Institute" id="Institute">
<?php
$sql = "SELECT * FROM Institute ";
$stmt = sqlsrv_query( $conn, $sql);
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true));
}
while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ) {
?>
<option value="<?php echo $row['InstituteID']; ?>"><?php echo $row['Institute_NAME']; ?></option>
<?php } ?>
</select>
<br>
Institutein select option on the change ofuniversityin select option??university idpresent ininstitute table.