How Can i get the value of an Selected object like select Id="foo" there are many options how can i get the value of the current selected?
+3
A:
The currently selected option in a <select>
can be retrieved by inspecting the value attribute:
Using jQuery:
$("#foo").val()
Without jQuery:
document.getElementById("foo").value
Philippe Leybaert
2010-01-20 11:07:25
`value` is a property, not an attribute. I blame jQuery for creating this muddle in people's minds with its ill-named `attr()` method.
Tim Down
2010-01-20 11:18:53
Thanks have a nice day
streetparade
2010-01-20 11:56:00
+2
A:
The surest way for cross-browser support is
var foo = document.getElementById('foo');
var val = foo.options[foo.selectedIndex].value;
Tim Down
2010-01-20 11:17:20