I have a list of objects services
in my thymeleaf context, and I have the following at my page:
<select id="inputService" name="idService" size="1">
<option th:each="service : ${services}" th:text="${service.name}" th:value="${service.idService}"/>
</select>
<p id="selectedServiceLimits"></p>
Each object from services
contains fields minAmount
and maxAmount
. How can I print into my p
element the these two fields of the selected service
in select
by javascript? And how can I print these two fields of the option that is selected when document is ready?
Thanks!
I have a list of objects services
in my thymeleaf context, and I have the following at my page:
<select id="inputService" name="idService" size="1">
<option th:each="service : ${services}" th:text="${service.name}" th:value="${service.idService}"/>
</select>
<p id="selectedServiceLimits"></p>
Each object from services
contains fields minAmount
and maxAmount
. How can I print into my p
element the these two fields of the selected service
in select
by javascript? And how can I print these two fields of the option that is selected when document is ready?
Thanks!
Share Improve this question asked May 31, 2015 at 10:13 another-programmeranother-programmer 8611 gold badge15 silver badges37 bronze badges1 Answer
Reset to default 2<script th:inline="javascript">
/*<![CDATA[*/
function showLimits() {
var services = /*[[${services}]]*/ null;
var selectedIndex = $("#inputService option:selected").index();
var service = services[selectedIndex];
$("#amountLimits").text("Мин. сумма: " + service.amountMin + ", макс. сумма: " + service.amountMax);
}
$(function() { showLimits(); });
/*]]>*/
</script>
<select id="inputService" name="idService" size="1" onChange="showLimits()">
That's the solution
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745597974a4635229.html
评论列表(0条)