JQuery: displaying a div if a special <select> option is selected?

I work on the address page of a shopping cart. There are 2 <select>boxes, one for the country, one for the region.

There are 6 standard countries, otherwise the user must select "Another country". All elements <option>have a numerical value. Another country is 241. What I need to do is hide the region <select>if the user selects another country and also displays a text box.

Any help MUCH appreciated!

+3
source share
3 answers

, , div. - (untested, , ). .

$(document).ready( function() {
  $('#YourSelectList').bind('change', function (e) { 
    if( $('#YourSelectList').val() == 241) {
      $('#OtherDiv').show();
    }
    else{
      $('#OtherDiv').hide();
    }         
  });
});
+6

, . , val() hide()/show() div.

0

, jQuery.

JavaScript :

document.getElementById('country_id').onchange = function()
{
    if (this.options[this.selectedIndex].value == 241) {
        document.getElementById('region_id').style.display = 'block';
    } else {
        document.getElementById('region_id').style.display = 'none';
    }
}

value , , select.options[select.selectedIndex].value. script.

-1

Source: https://habr.com/ru/post/1712432/


All Articles