最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

java - JavaScript + Thymeleaf - select onchange - Stack Overflow

matteradmin6PV0评论

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

Post a comment

comment list (0)

  1. No comments so far