tags:

views:

41

answers:

2

I tried all these for selected value of 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();

these all worked well in mozilla but not in IE

is any alternative

A: 

You could try the jQuery Form Plugin.

Tomas Lycken
Only useful if he's submitting the form via ajax.
Andy E
@Andy, I disagree - he could still make use of the `.value()` function within the plugin, without having to use the ajax functionality.
Tomas Lycken
@Tomas: but then it's no different to using `.val()` to get the value of the element, which is what the plugin uses in its underlying code.
Andy E
+1  A: 

The 4th of your attempts is the most straightforward way to get the selected value of a select element and it should work.

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

I wrote a quick and dirty example for you at jsfiddle.net, showing that it works. This means that your selector is probably wrong. Check and make sure the select element has id="inventory_rule" and make sure that id attribute is also unique on the page. Don't forget the var keyword if it's the first time you're declaring the variable.

EDIT: highlighted the part about making sure the id attribute is unique, a non-unique id will definitely cause problems in IE.

Andy E