User9895
User9895

Reputation: 313

How to combine two dropdownlists change event JQuery function into one?

I want to combine these two function into one. #Ctry,#Yd are dropdown lists. Please show me the path. Thank you in advance.

$('#Ctry,#Yd').change(function () {
  var url = '@Url.Action("tal", "St")'
  $('#Rial').load(url, { ctry: $('#Ctry').val(),yd: $('#Yd').val() })
});

$('#Ctry,#Yd').change(function () {
  var url = '@Url.Action("tala", "St")'
  $('#con').load(url, { ctry: $('#Ctry').val(),yd: $('#Yd').val() })
});

Upvotes: 0

Views: 16

Answers (1)

Phil
Phil

Reputation: 164796

Can't you just use one .change() handler and just put the two .load() calls in it with their respective URLs?

$('#Ctry, #Yd').change(function () {
  let data = {
    ctry: $('#Ctry').val(),
    yd: $('#Yd').val()
  }
  let rialUrl = '@Url.Action("tal", "St")'
  let conUrl = '@Url.Action("tala", "St")'
  $('#Rial').load(rialUrl, data)
  $('#con').load(conUrl, data)
})

Upvotes: 1

Related Questions