0

Is there any other way to process a form when a person choose one option from one select it changes the results in other select. Otherwise Safari browser does not execute my code.

Here is the jQuery code:

$(document).ready(function(){


    $('select[name=nm_field_3]').click(function(){
        var other_options = $('select[name=nm_field_4] option[value="120cm"]');
        var selected_option = $('select[name=nm_field_3] option:selected');
        if(selected_option.text() == 'Brown')
        {
            other_options.hide();
        }

        else
        {
            other_options.show();
        }
    });

});

Here js fiddle: http://jsfiddle.net/aq710agd/2/

I mean this works but not all of the browsers support it. That's why I'm looking for a proper way.

Thanks for help :)

aynber
  • 22,380
  • 8
  • 50
  • 63
user2204367
  • 145
  • 3
  • 3
  • 16
  • update this [Demo](http://jsfiddle.net/mohamedyousef1980/aq710agd/1/) to let us understand what you trying to do – Mohamed-Yousef Dec 03 '15 at 16:45
  • You can't hide `options` from `select`. You can in some browsers but not in Chrome nor IE. You need to `remove()` options and then add them back if needed: see here : http://stackoverflow.com/questions/1271503/hide-options-in-a-select-list-using-jquery – Victor Levin Dec 03 '15 at 16:46

1 Answers1

0

You need to listen to change event on the 'first' select, And update the options on the 'second'.

Working example:

var other_select = $('select[name=nm_field_4]');
var other_options = $('select[name=nm_field_4] option[value="120cm"]');
//Listen to change event on the 'first' select
$('select[name=nm_field_3]').change(function () {
    //Getting the selected value after the change
    var currentValue = $(this).val();
    //Then do your logic
    if (currentValue === "Brown") {
        other_options.detach();
    } else {
        other_select.append(other_options);
    }

});
Adi Darachi
  • 2,137
  • 1
  • 16
  • 29
  • You see the probem is that safari does not support .show and .hide as well as Internet Explorer. Is there any other way? – user2204367 Dec 03 '15 at 16:59