0
 function Test_Country_OnItemSelection(ddlCountryId, ddlcityId, DataList) {
    var ddlCountry = document.getElementById(ddlCountryId);
    var selectedValue = ddlCountry.options[ddlCountry.selectedIndex].value;
    var selectedText = ddlCountry.options[ddlCountry.selectedIndex].text;

    var ddlcity = document.getElementById(ddlcityId);
}

I have the above JavaScript function in which I'm passing parameters for dropdownlists ddlCountryId and ddlcityId. I then pass the final parameter DataList which is a C# object defined as List<City> and it contains a CityId, CityName & CountryID.

How can I convert the DataList object to a JavaScript array that I can then filter on CountryID == selectedValue and then refresh dropdownlist ddlcity after applying my filter?

Dai
  • 141,631
  • 28
  • 261
  • 374
StackTrace
  • 9,190
  • 36
  • 114
  • 202
  • Unrelated protip: You don't need to use `ddlCountry.options[ddlCountry.selectedIndex].value` - just use `ddlCountry.value`. Also, it is incorrect to refer to `` elements on desktop browsers, on mobile devices they're not drop-downs at all. – Dai Feb 07 '22 at 13:24
  • @Dai That's a distinction without a difference (render JSON in a `script` and it's JavaScript). The *accepted* answer uses ajax, but the *questions* are the same. There are answers on that question which do not use ajax and will render the array inline. – Heretic Monkey Feb 07 '22 at 13:30
  • @Dai I don't care. The fact that you find an answer sub-par does not make the *questions* not duplicates. If you have a better answer, *answer the duplicate*. If you have a problem with an answer, *comment on the answer*. Don't say the questions are not duplicates just because you don't like the answers. – Heretic Monkey Feb 07 '22 at 13:39

0 Answers0