Код: Выделить всё
Generatie *
Alege mai intai un model
Combustibil *
Alege mai intai o generatie
Engine *
Alege mai intai un combustibil
Это код JS:
Код: Выделить всё
$(document).ready(function() {
$('#car-generation').on('change', function() {
var generation_id = $(this).val();
if (generation_id > 0) {
$.ajax({
type: 'POST',
url: 'ajax.php',
data: 'generation_id=' + generation_id,
success: function(html) {
$('#car-fuel').html(html);
}
});
} else {
$('#car-fuel').html('Alege mai intai o generatie');
}
});
$('#car-fuel').on('change', function() {
var fuel_id = $(this).val();
if (fuel_id > 0) {
$.ajax({
type: 'POST',
url: 'ajax.php',
data: {
fuel_id: 'fuel_id',
generation_id: 'generation_id'
},
success: function(html) {
$('#car-engine').html(html);
}
});
} else {
$('#car-engine').html('Alege un motor');
}
});
$('#car-engine').on('change', function() {
var engine_id = $(this).val();
if (engine_id > 0) {
$.ajax({
type: 'POST',
url: 'ajax.php',
data: 'engine_id=' + engine_id,
success: function(html) {
$('#car-transmission').html(html);
}
});
} else {
$('#car-transmission').html('Alege o transmisie');
}
});
});
Код: Выделить всё
Подробнее здесь: [url]https://stackoverflow.com/questions/78831312/using-two-variables-in-ajax-to-refresh-an-input-with-values-from-the-database[/url]
Мобильная версия