0

I have 2 select boxes , both with same items and values , each assigned unique ID

When i select an item from one select option box , i want to hide the same item in the other select box.

This works fine on desktop , but IOS , i can not get the option to hide

Setup a fiddle here - https://jsfiddle.net/m359c4sv/1/

<select id="one">
    <option value="0001">item 1</option>
    <option value="0002">item 2</option>
    <option value="0003">item 3</option>
    <option value="0004">item 4</option>
    <option value="0005">item 5</option>
</select>

<select id="two">
    <option value="0001">item 1</option>
    <option value="0002">item 2</option>
    <option value="0003">item 3</option>
    <option value="0004">item 4</option>
    <option value="0005">item 5</option>
</select>


$(document).on('change', '#one', function () {
    id_one = $(this).val();
    $('#two option').show();
    $('#two option[value="' + id_one + '"]').hide();
});

$(document).on('change', '#two', function () {
    id_two = $(this).val();
    $('#one option').show();
    $('#one option[value="' + id_two + '"]').hide();
});
MShack
  • 642
  • 1
  • 14
  • 33

1 Answers1

1

From time to time, iOS seems to not support hide() Hiding DIVs using Jquery is not working in Safari (iOS)

You could go with addClass() and removeClass() :

<select id="one">
    <option value="0001">item 1</option>
    <option value="0002">item 2</option>
    <option value="0003">item 3</option>
    <option value="0004">item 4</option>
    <option value="0005">item 5</option>
</select>

<select id="two">
    <option value="0001">item 1</option>
    <option value="0002">item 2</option>
    <option value="0003">item 3</option>
    <option value="0004">item 4</option>
    <option value="0005">item 5</option>
</select>


.showMe {
  display: block;
}

.hideMe {
  display: none;
}


$(document).on('change', '#two', function () {
    id_two = $(this).val();

    $('#one option[value*="0"]').addClass('showMe').removeClass('hideMe');
    $('#one option[value="' + id_two + 
    '"]').removeClass('showMe').addClass('hideMe');
});

$(document).on('change', '#one', function () {
    id_one = $(this).val();

    $('#two option[value*="0"]').addClass('showMe').removeClass('hideMe');
    $('#two option[value="' + id_one + 
    '"]').removeClass('showMe').addClass('hideMe');
});
cheesyMan
  • 1,494
  • 1
  • 4
  • 13
  • thanks , that is what i was working on now , no idea why hide not working on options , but adding a class like you said it just as good. Thanks – MShack Apr 02 '22 at 16:58
  • 2
    skip that effort , even using css to hide the select option is not working in IOS – MShack Apr 02 '22 at 17:04