javascript – How can i select multiple select in dropdown-ThrowExceptions

Exception or error:

So I’m making a Drop Down Multiple Select but I don’t know how to properly change the scripts or the function. Here the multiple select here is the code for the script or function:

       function show_subj(){
        var studID = $('#ddl_stud').val();
        console.log(studID);
        if(studID){
            $.ajax({
                type:'POST',
                url:'grade_dropdown.php',
                data: 'stud_id='+studID,
                success:function(html){
                    $('#ddl_subj').html(html);
        console.log($('#ddl_subj').html(html));
                }
            }); 
        }
    }
How to solve:

studID will be an array for a multiple select.

Use an object for the data parameter instead of a string.

function show_subj(){
    var studID = $('#ddl_stud').val();
    console.log(studID);
    if(studID){
        $.ajax({
            type:'POST',
            url:'grade_dropdown.php',
            data: {stud_id: studID},
            success:function(html){
                $('#ddl_subj').html(html);
    console.log($('#ddl_subj').html(html));
            }
        }); 
    }
}

In PHP, $_POST['stud_id'] will be an array of all the selected option values.

Leave a Reply

Your email address will not be published. Required fields are marked *