I have 3 select Boxes. From the selection of first select Box, i am getting the options for second select Box. That comes easily using the jQuery Ajax. But after this second select box on change is not working for getting the Jquery ajax output, which i have to put in third select box. I have following three select Boxes 1) College select Box 2) Course type select box 3) Branch type select Box.
From college select box, i select a college, then using Jquery:ajax i got course type options for Course type select box. But when i am selecting any one option from Course type then it is not working. I am using Php for ajax.
my code is follows:
<script> $("#collegename").change(function() { var collegeID = $("#collegename").val(); $.ajax({ url: "ajax/getCollegeBranchDetailsTotal.php", type: "POST", data: {ID : collegeID}, dataType: "json", success: function(data){ if(data.success){ var outputHtml = ''; var SelectStart = '<select id="coursename" name="coursename"><option value=""> Select a Course </option>'; var SelectEnd = '</select>'; var options = ''; if(data.branchData){ $.each( data.branchData, function( course, branchdetails ) { var optionParam = '<option value='+ data.courseData[course] +'> ' + course + '</option>'; options = options + optionParam; }); } outputHtml = SelectStart + options + SelectEnd; $(".courseDiv").html(outputHtml); } } }); }); $("#coursename").on('change', function() { var collegeID = $("#collegename").val(); $.ajax({ url: "ajax/getCollegeBranchDetailsTotal.php", type: "POST", data: {ID : collegeID}, dataType: "json", success: function(data){ if(data.success){ var outputHtml = ''; if(data.branchData){ var SelectStart = '<select id="branchname" name="branchname"><option value=""> Select a Branch </option>'; var SelectEnd = '</select>'; var options = ''; $.each( data.branchData, function( course, branchdetails ) { $.each( branchdetails, function( id, name ) { var optionParam = '<option value="'+ id +'"> ' + name + '</option>'; options = options + optionParam; }); }); outputHtml = SelectStart + options + SelectEnd; } $(".branchNames").html(outputHtml); } } }); }); </script> <body> <div class="block"> <div class="label">College Name:</div> <div class="collegeDiv"> <select id="collegename" name="collegename" /> <option value=''> Select a College </option> <?php foreach ($collegeNames as $id => $values) { print "<option value='$id'> " . $values["Name"] . "</option>"; } ?> </select><br /> </div> </div> <div class="block"> <div class="label">Course Name: </div> <div class="courseDiv"> <select id="coursename" name="coursename" /> <option value=''> Select a Course </option> </select><br /> </div> </div> <div class="block"> <div class="label">Branch Name: </div> <div class="branchNames"> <select id="branchname" name="branchname" /> <option value=""> Select a Branch </option> </select><br /> </div> </div> </body>