Hi,
I am trying to create dynamic selection boxes with Jquery.
Due to requirements, I have 5 selection boxes with similar Class contents e.g. Class A, Class B, Class C, etc. I have another 5 Student selection boxes besides each of the Class selection boxes.
So the idea is that when I select a class selection box, javascript will check on the selection and proceed to send the selection value using GET action, and return the contents for my Student selection box.
I already have a working script. But it is only working for one Class selection box, and if I need to have it running for the rest of the 4 Class selection boxes, I will have to create 4.js script with the different values.
May I know is there any way that I could just use 1 js and works for all the 5 Class selection boxes? Maybe a loop, or etc?
Working js for 1 selection box:
function class_change() {
$('#class1').change(update_students);
// the rest of the class sel boxes are named as #class2 #class3, etc.
}
function update_students() {
var class = $('#class1').val();
var seat = $('#seat1').val();
$.get('getStuds.php?seatno='+seat+'&class='+class, showStudents);
}
function showStudents(result) {
$('#show_student1').html(result);
}
$(document).ready(class_change);
Thank you very much.