java - JavaScript + Thymeleaf - select onchange - Stack Overflow

I have a list of objects services in my thymeleaf context, and I have the following at my page:<sele

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 badges
Add a ment  | 

1 Answer 1

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

相关推荐

  • java - JavaScript + Thymeleaf - select onchange - Stack Overflow

    I have a list of objects services in my thymeleaf context, and I have the following at my page:<sele

    13小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信