java - JavaScript + Thymeleaf - select onchange -
i have list of objects services
in thymeleaf context, , have following @ 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 services
contains fields minamount
, maxamount
. how can print p
element these 2 fields of selected service
in select
javascript? , how can print these 2 fields of option selected when document ready?
thanks!
<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 solution
Comments
Post a Comment