asked on
reverseLogic[i].value.indexOf("data-countrycode=" + "''"+ val +"''")
jQuery(function($) {
var reverseLogic = [];
$("#StateId option:gt(0)").each(function(i, v) {
reverseLogic.push({ value: $(this).val(), text: $(this).text() });
});
$("#CountryId").change(function() {
var putAllBack = $(this).prop("selectedIndex") == 0;
var val = $(this).val();
$("#StateId option:gt(0)").remove();
for (var i = 0; i < reverseLogic.length; i++) {
if (putAllBack || reverseLogic[i].value.indexOf("-" + val) > 0) {
$("#StateId").append("<option value='" + reverseLogic[i].value + "'>" + reverseLogic[i].text + "</option>");
}
}
}).change();
});
<select data-val="true" id="CountryId" name="CountryId"><option value="Selects items">Country*</option>
<option value="25">Canada</option>
<option value="126">United States</option>
</select>