2

There are 2 drop-down, 2nd is dependent on 1st. The same code is working fine in Chrome/Firefox, but not working in IE

Below is the JQuery Code:

$(document).ready(function() {
    $("#CurrencyPair").children('option:gt(0)').hide();
    $("#part1currency").change(function() {
        $("#CurrencyPair").children('option').hide();
        $("#CurrencyPair").children("option[value^=" + $(this).val() + "]").show();
    });
});

Below is the HTML code :

<select name="part1currency" id="part1currency">
    <option value="Select">Select</option>
    <option value="EUR">EUR</option>
    <option value="USD">USD</option>
    <option value="GBP">GBP</option>
</select>

<select name="CurrencyPair" id="CurrencyPair">
    <!--Below shows when '1 column' is selected is hidden otherwise-->
    <option value="Select">--Select--</option>

    <!--Below shows when '2 column' is selected is hidden otherwise-->
    <option value="EUR/USD">EUR/USD</option> 
    <option value="col2_sm">layout 2</option>

    <!--Below shows when '3 column' is selected is hidden otherwise-->
    <option value="USD/EUR">USD/EUR</option>
    <option value="col3_ssm">layout 4</option>
    <option value="col3_sms">layout 5</option>
</select>
udit khare
  • 354
  • 2
  • 10
  • I too am having the same issue with find not working in IE – BostonMacOSX Nov 12 '15 at 20:47
  • Possible duplicate of [jQuery .find() doesn't return data in IE but does in Firefox and Chrome](https://stackoverflow.com/questions/562283/jquery-find-doesnt-return-data-in-ie-but-does-in-firefox-and-chrome) – avs099 Oct 15 '18 at 20:26

1 Answers1

0

I have found one solution for the above question of mine.

$(document).ready(function() {
    var optarray = $("#CurrencyPair").children('option').map(function() {
        return {
            "value": this.value,
            "option": "<option value='" + this.value + "'>" + this.text + " `enter code here`</option>"
        }
    })

    $("#part1currency").change(function() {
        $("#CurrencyPair").children('option').remove();
        var addoptarr = [];
        addoptarr.push(optarray[0].option);
        for (i = 1; i < optarray.length; i++) {
            if (optarray[i].value.substring(0, 3).indexOf($(this).val()) > -1) {
                addoptarr.push(optarray[i].option);
            }


        }
        $("#CurrencyPair").html(addoptarr.join(''))
    }).change();
})
udit khare
  • 354
  • 2
  • 10