Reputation: 139
How should I get an form input selected value using jQuery
<form:select path="amtAppMonitResltVO.monitStat" id="amtAppMonitResltVO.monitStat" cssClass="state">
<option value="">선택</option>
<form:options name="monit" items="${apps}" itemValue="subCd" itemLabel="subCdNm" />
</form:select>
<img src="<c:url value='/resources/img/read.png'/>" class="read" id="appStatSearch"></td>
Upvotes: 3
Views: 185
Reputation: 2984
You just need get the .val()
of the amtAppCollInfoVO_mkType
select input:
var some_var = $('#amtAppCollInfoVO_mkType').val();
For pure Javascript just switch .val()
to .value
Note that your current option does not have a value.
Note that since you have the .
in your id you have to add double \
to your Javascript code:
<script>
$(function() {
$('#amtAppMonitResltVO\\.monitStat').on('click', function() {
var moniStat = $('#amtAppMonitResltVO\\.monitStat').val();
console.log(moniStat);
})
})
</script>
Credit goes here for this answer.
Upvotes: 4
Reputation: 1
The one option you have has no value, but if you set a value for it, you could use a selector like the following to get the value of the first selected option.
$("#amtAppCollInfoVO_mkType option:selected").val()
If you wanted all the option values in an array you could use the map method.
var arr = $("#amtAppCollInfoVO_mkType option").map(function(){return $(this).val();}).get();
Upvotes: 0