cd67-listes.js 884 B

123456789101112131415161718192021222324
  1. $(document).ready(function () {
  2. //gestion des listes déroulantes imbriquées
  3. $(".liste-principale").change(function () {
  4. var id = $(this).val();
  5. console.log(id);
  6. var dataurl = $(this).attr("data");
  7. $.ajax({
  8. url: dataurl,
  9. dataType: 'json',
  10. data: { Id: id },
  11. success: function (data) {
  12. var select = $(".liste-secondaire");
  13. select.empty();
  14. $.each(data, function (index, itemData) {
  15. select.append($('<option/>', {
  16. value: itemData.Value,
  17. text: itemData.Text
  18. }));
  19. });
  20. if ($('.liste-secondaire option').length == 2) $('.liste-secondaire option').eq(1).prop('selected', true).trigger("change");
  21. }
  22. })
  23. });
  24. });