I am currently working with jQuery and have encountered an issue regarding the reset
functionality for a dropdown list. Specifically, after adding default options in both
Arabic and English, the reset button does not display correctly.
When a value is selected, I want to show a reset button (denoted as "X").
However, if no option is selected, the dropdown should display either "Select port" or "???? ????" without showing the reset button.
Before changing the language to Arabic or English, the reset button appears as expected. Here is the relevant code snippet:
row += "";
var countriesPorts = Result.d.P_PORTS.filter(d => d.COUNTRY_ID == Result.d.P_DISPATCH_DATA[i].PICKUP_COUNTRY_ID);
if (countriesPorts != null) {
if (countriesPorts.length > 0) {
for (var j in countriesPorts) {
row += " " + countriesPorts[j].PORT_NAME + " ";
}
row += " ";
}
After switching to Arabic or English, the reset button ("X") does not appear. The code for the dropdown with the default option is as follows:
var defaultOption = MYLang.ReturnLang() == "ar-KW" ? "???? ????" : "select port";
row += "" +
"" + defaultOption + "";
var countriesPorts = Result.d.P_PORTS.filter(d => d.COUNTRY_ID == Result.d.P_DISPATCH_DATA[i].PICKUP_COUNTRY_ID);
if (countriesPorts != null && countriesPorts.length > 0) {
for (var j in countriesPorts) {
row += "" + countriesPorts[j].PORT_NAME + "";
}Additionally, I would like an image to illustrate the reset button in red on the second row.


Amira BedhiafiRank #601 · 4K reputationPosted Jan 19, 2025, 1:24 PM EST
Can you try the following :
function updateDropdown(Result, i) { var defaultOption = MYLang.ReturnLang() === "ar-KW" ? "???? ????" : "Select port"; var row = ` ${defaultOption} X `; var countriesPorts = Result.d.P_PORTS.filter( d => d.COUNTRY_ID === Result.d.P_DISPATCH_DATA[i].PICKUP_COUNTRY_ID ); if (countriesPorts && countriesPorts.length > 0) { countriesPorts.forEach(port => { $(`#ddl_Port${Result.d.P_DISPATCH_DATA[i].DISPATCH_RECID}`).append( `${port.PORT_NAME}` ); }); } $(`#ddl_Port${Result.d.P_DISPATCH_DATA[i].DISPATCH_RECID}`).change(function () { var selectedValue = $(this).val(); if (selectedValue) { $(this).siblings(".reset-btn").show(); } else { $(this).siblings(".reset-btn").hide(); } }); $(`#ddl_Port${Result.d.P_DISPATCH_DATA[i].DISPATCH_RECID}`) .siblings(".reset-btn") .click(function () { var dropdown = $(this).siblings("select"); dropdown.val("").trigger("change"); }); } function refreshDropdowns() { $(".dropdown-container").each(function () { var dropdown = $(this).find("select"); var resetBtn = $(this).find(".reset-btn"); var defaultOption = MYLang.ReturnLang() === "ar-KW" ? "???? ????" : "Select port"; dropdown.find("option[value='']").text(defaultOption); if (!dropdown.val()) { resetBtn.hide(); } }); }