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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
| $(document).ready(function() {
var $mat = $('#mat');
var $mat2 = $('#mat2');
$.getJSON("{% url search_prop %}", function(data) { // appel fonction de filtrage
family = data['val_prop'];
$('.target').empty();
$.each(family, function(ind, item) {
$('.target').append('<option value="'+ ind +'">'+ item +'</option>');
val = $('option:selected',this).text();
$(this).next().text(val);
}); // each
});
$mat.on('change', function() {
var val = $(this).val();
$.getJSON("{% url search_prop2 %}", {'reference': materiau }, function(data) { // appel fonction de filtrage
family = data['val_mat'];
$('.target2').empty();
$.each(family, function(ind, item) {
$('.target2').append('<option value="'+ ind +'">'+ item +'</option>');
val = $('option:selected',this).text();
$(this).next().text(val);
}); // each
var materiau2 = $('#mat2 option:selected').text();
document.forms["general"].champ2.value= materiau2;
});
}); // onchange
});
<body>
<form id= "testjson" name= "general" action="{% url chercher_filtre1 %}" method= "get" onsubmit = "">
<td>
<select class="target" name="mat" id="mat" title="Select one" style="background-color:#F0F8FF;" >
<option value="" >..........................................</option>
<option></option>
</select>
</td>
<td>
<select class="target2" name="mat2" id="mat2" title="Select one" style="background-color:#F0F8FF;" >
<option value="" >..........................................</option>
<option></option>
</select>
</td> |
Partager