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
|
$("select#tri").change(function(){
// Post string
var post_string = "type=" + $(this).val();
alert(post_string);
$("<select id='"+post_string+"' name='"+post_string+"'><option>test</option></select>").appendTo("#formtri");
// Send the request and update sub category dropdown
$.ajax({
type: "POST",
data: post_string,
dataType: "json",
cache: false,
url: 'json/select2.php',
timeout: 2000,
error: function() {
alert("Failed to submit");
},
success: function(data) {
// Clear all options from sub category select
$("select#"+post_string).remove();
// Fill sub category select
$.each(data, function(i, j){
var row = "<option value=\"" + j.value + "\">" + j.text + "</option>";
$(row).appendTo("select#"+post_string);
});
}
});
}); |
Partager