.val () jquery not working for selected item in IE

I tried all this for the selected value of the select element

inventory_rule = $("#inventory_rule :selected").attr('value'); inventory_rule = $("#inventory_rule option:selected").val(); inventory_rule = $("#inventory_rule").attr('value'); inventory_rule = $("#inventory_rule").val(); 

they all worked well in mozilla but not in IE

- any alternative

+4
source share
3 answers

The fourth of your attempts is the easiest way to get the selected value of the select element, and it should work.

 var inventory_rule = $("#inventory_rule").val(); 

I wrote a quick and dirty example for you on jsfiddle.net, showing that it works. This means that your selector is probably wrong. Check and verify that the select element has id="inventory_rule" and make sure that the id attribute is also unique on the page . Do not forget the var keyword if this is the first time you declare a variable.

EDIT: highlight the part that the id attribute is unique, not a unique identifier will certainly cause problems in IE.

+2
source

Just met this before.

upon receiving value

 <select> 

the IE 10 tag inserts spaces before and after the value. so just trim the value and it will solve your worries.

 var inventory_rule = $.trim($("#inventory_rule").val()); 
+1
source

You can try jQuery Form Plugin .

0
source

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


All Articles