簡體   English   中英

如何從中獲取價值 <select>並將其放在隱藏的JSTL中

[英]How to retrieve value from <select> and put it in hidden JSTL

我有一個相當愚蠢的問題,但仍然無法解決它的問題...概念是要有一個提示用戶選擇主題的選擇值。 選擇后,我需要以下面使用的每種形式存儲該主題ID,以便我可以檢索該主題,並且我不想為我需要的每種單個表單使用不同的選擇。 這是下面的代碼:

<div class="input-field col s12">
                            <select>
                                <c:forEach var="subjectItem" items="${subjectList }">
                                    <option value="${subjectItem.id }">${subjectItem.subjectName }</option>
                                </c:forEach>
                            </select> <label>For subject</label>
                        </div>
......
.....
<form method="POST" action="subject-add-school-deadline"
                                    id="deadlineSchoolForm">
----! Here is should retrieve that data from select !-------
                                    <div class="row">
                                        <div class="input-field col s6">
                                            <input id="schoolD_title" type="text" class="validate"
                                                name="title""> <label
                                                for="schoolD_title">Title</label>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="input-field col s12 l12 ">

                                            <textarea id="schoolD_desc" name="description"
                                                class="materialize-textarea validate" form="deadlineSchoolForm"></textarea>
                                            <label for="schoolD_desc">Description</label>
                                        </div>
                                    </div>
                                    <div class="row">
                                <label class="col s2">Deadline date</label> <input type="date"
                                    class="datepicker col s4" name="date">
                            </div>
                            <div class="row right-align">
                        <button class="waves-effect waves-teal btn-flat" type="submit"
                            name="action" >
                            Add <i class="material-icons right">input</i>
                        </button>
                    </div>
                                </form>
----MORE FORMS BELOW ------
.....
.....

請注意,我不需要類似的東西

<select form="form1>

因為我需要多種形式的選擇值。 任何幫助將不勝感激。 謝謝!!

我使用jQuery在名為title所有輸入中設置值。 這樣可以解決您的問題嗎?

JS小提琴

重要部分:

 <script type="application/javascript">
    $("select#foo").change(function() {
      $("input[name='title']").val($("select#foo").val());
    });
  </script>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM