views:

63

answers:

3

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
`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
Thanks have a nice day
streetparade
+1  A: 
document.getElementById('foo').value

?

Kemo
sorry, Philippe answered while I was answering
Kemo
+2  A: 

The surest way for cross-browser support is

var foo = document.getElementById('foo');
var val = foo.options[foo.selectedIndex].value;
Tim Down