Skip to content Skip to sidebar Skip to footer

Jquery To Auto-populate A Select Input From Another Select Input

EDIT 1 I am getting courseID from this code: $coursesOutput = ''; while($row = mysql_fetch_array($result2)){ $courseID = $row

Solution 1:

Where does courseID come from? Try logging it into the console. Does this help?

functionpopulateTee(courseID){
   $.ajax({
           url: 'includes/populate_tee.php?courseID=' + courseID,
           success: function(data) {
                    //Assuming you're returning the tees list as an indexed arrayvar ops = '';
                    for(var i=0; i<data.length; i++){
                        ops += '<option>'+data[i]+'</option>';
                    }
                    $("#tee").html(ops);
           }
   });
 }

Solution 2:

Instead of using onChange event on select i suggest use of jquery .change() method. Try following code it should solve the problem.

 $('#course').on('change', function () {
          var courseID = $(this).val();

          $.ajax({
                type: "post",
                url: 'includes/populate_tee.php?courseID=' + courseID,
                success: function(data) {
                $("#tee").html(data);
               }
              });


      });

Post a Comment for "Jquery To Auto-populate A Select Input From Another Select Input"