Reputation: 173
I have following select list from which user can select multiple option
<select size="6" onblur="validatevalumethod()" multiple="" id="valumethod[]" name="valumethod[]">
<option value="0">Select Asset</option>
<option value="OC">ORIGINAL COST</option>
<option value="OCUIP">ORIGINAL COST USING INDEXED PRICES</option>
<option value="RC">REPLACEMENT COST</option>
<option value="OCCR">ORIGINAL COST CONSIDERING REVALUATION</option>
<option value="OCUIPCR">ORIGINAL COST USING INDEXED PRICES & CONSIDERING REVALUATION</option>
<option value="RCCR">REPLACEMENT COST CONSIDERING REVALUATION</option>
</select>
I need to fetch the value selected by user in javascript but dont know how to do this please help me.
Upvotes: 2
Views: 169
Reputation: 360
You can use pure javascript as in : document.getElementById('valumethod[]').value
Upvotes: 1
Reputation: 10288
Here's a very simple code that tells you how many you selected on every change:
For the Html Code:
<html>
<body>
<select multiple="true">
<option>Volvo</option>
<option>Saab</option>
<option>Mercedes</option>
<option>Audi</option>
</select>
</body>
</html>
Use this jQuery Code:
$("select").change(function() {
alert($("option:selected").length);
});
Here's a live example: http://jsfiddle.net/hesher/3M36e/
Upvotes: 1
Reputation: 2620
I think that the following solution is better to fetch VALUES :
$("#list option:selected").val();
Upvotes: 1
Reputation: 5647
With jQuery you could do
$("#list option:selected").text();
to get the text of the selected option
$("#list option:selected").val();
to get the value behind the selected option
EDIT:
where #list is the id of your select tag
Upvotes: 1