Howto get the Value of an Selected Object in Javascript
How Can i get the value of a开发者_开发百科n Selected object like select Id="foo" there are many options how can i get the value of the current selected?
The surest way for cross-browser support is
var foo = document.getElementById('foo');
var val = foo.options[foo.selectedIndex].value;
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
document.getElementById('foo').value
精彩评论