2

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 Answers 3

4

The surest way for cross-browser support is

var foo = document.getElementById('foo');
var val = foo.options[foo.selectedIndex].value;
Sign up to request clarification or add additional context in comments.

Comments

3

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

1 Comment

value is a property, not an attribute. I blame jQuery for creating this muddle in people's minds with its ill-named attr() method.
2
document.getElementById('foo').value

1 Comment

sorry, Philippe answered while I was answering

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.