Bonjour

je voudrai créer un code qui permet de donner au utilisateur de choisi 10 universities a chaque fois le utilisateur choisi l'universities la branche sera charger automatic son changer la page

mais le probleme le premier cobobox uniquement function,
voila mon code :
Nom : un.png
Affichages : 288
Taille : 32,9 Ko

page item.php
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
$(document).ready(function(){
        $("#faculty").change(function(){
            var faculty_id = $(this).val();
            var url = '<?php echo osc_ajax_plugin_url('universitys_attributes/ajax.php') . '&facultyId='; ?>' + faculty_id;
            var result = '';
            if(faculty_id != '') {
                $("#branch").attr('disabled',false);
                $.ajax({
                    type: "POST",
                    url: url,
                    dataType: 'json',
                    success: function(data){
                        var length = data.length;
                        if(length > 0) {
                            result += '<option value="" selected><?php _e('Select a branch', 'universitys_attributes'); ?></option>';
                            for(key in data) {
                                result += '<option value="' + data[key].pk_i_id + '">' + data[key].s_name + '</option>';
                            }
                        } else {
                            result += '<option value=""><?php _e('No results', 'universitys_attributes'); ?></option>';
                        }
                        $("#branch").html(result);
                    }
                 });
             } else {
                result += '<option value="" selected><?php _e('Select a branch', 'universitys_attributes'); ?></option>';
                $("#branch").attr('disabled',true);
                $("#branch").html(result);
             }
        });
});
Code php : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 <div class="row _200">
<h2><?php _e('Universities', 'universitys_attributes') ; ?></h2>
<table id="tab_st" border="1">
<tr ><th>Universities</th><th>Department</th><th>Year</th></tr>
<?php for ($i = 1; $i <= 10; $i++) { ?>
<tr> 
<td> 
<?php echo "".$i."";?>
<select name='faculty' id='faculty_<?php echo $i;?>' >
            <option value=""><?php _e('Select a faculty', 'universitys_attributes'); ?></option>
            <?php foreach($facultys as $a){ ?>
            <option value="<?php echo $a['pk_i_id']; ?>" <?php if(@$detail['fk_i_faculty_id'] == $a['pk_i_id']) { echo 'selected'; } ?>><?php echo $a['s_name']; ?></option>
            <?php } ?>
</select> </td> 
        <td> <select name="branch" id="branch">
            <option value="" selected><?php _e('Select a branch', 'universitys_attributes'); ?></option>
            <?php foreach($branchs as $a) { ?>
            <option value="<?php echo $a['pk_i_id']; ?>" <?php if(@$detail['fk_i_branch_id'] == $a['pk_i_id']) { echo 'selected'; } ?>><?php echo $a['s_name']; ?></option>
            <?php } ?>
        </select> </td> 
        <td> </td> 
        </tr>
<?php }?>
</table>
 </div>

page ajax.php

Code php : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
<?php
 require_once 'ModelUnivesity.php' ;
 
    if( Params::getParam("facultyId") != '' ) {
        $branchs = ModelUnivesity::newInstance()->getBranchs( Params::getParam("facultyId") );
        echo json_encode($branchs) ;
    }
?>

merci d'avance