如何从<select>中检索值并将其放入隐藏的JSTL中

时间:2017-05-23 11:16:34

标签: javascript java jquery spring jstl

我有一个相当愚蠢的问题,但仍然无法找到解决方法...概念是有一个选择值,提示用户选择一个主题。在选择后,我需要将我在下面使用的每种形式中存储该主题ID,以便我可以检索该主题,并且我不想对我需要的每个单独形式使用不同的选择。这是下面的代码: &lt; div class =&#34; input-field col s12&#34;&gt;                             &LT;选择&GT;                                 &lt; c:forEach var =&#34; subjectItem&#34; items =&#34; $ {subjectList}&#34;&gt;                                     &lt; option value =&#34; $ {subjectItem.id}&#34;&gt; $ {subjectItem.subjectName}&lt; / option&gt;                                 &LT; / C:的forEach&GT;                             &LT; /选择&GT; &lt; label&gt;对于主题&lt; / label&gt;                         &LT; / DIV&GT; ...... ..... &lt; form method =&#34; POST&#34;行动=&#34;被摄体附加校期限&#34;                                     ID =&#34; deadlineSchoolForm&#34;&GT; ----!这应该从select中检索出来的数据!-------                                     &lt; div class =&#34; row&#34;&gt;                                         &lt; div class =&#34; input-field col s6&#34;&gt;                                             &lt; input id =&#34; schoolD_title&#34;类型=&#34;文本&#34;类=&#34;验证&#34;                                                 名称=&#34;标题&#34;&#34;&GT; &LT;标签                                                 用于=&#34; schoolD_title&#34;&GT;标题&LT; /标签&gt;                                         &LT; / DIV&GT;                                     &LT; / DIV&GT;                                     &lt; div class =&#34; row&#34;&gt;                                         &lt; div class =&#34; input-field col s12 l12&#34;&gt;                                             &lt; textarea id =&#34; schoolD_desc&#34;命名=&#34;描述&#34;                                                 class =&#34; materialize-textarea validate&#34;形式=&#34; deadlineSchoolForm&#34;&GT;&LT; / textarea的&GT;                                             &lt; label for =&#34; schoolD_desc&#34;&gt;说明&lt; / label&gt;                                         &LT; / DIV&GT;                                     &LT; / DIV&GT;                                     &lt; div class =&#34; row&#34;&gt;                                 &lt; label class =&#34; col s2&#34;&gt;截止日期&lt; / label&gt; &lt;输入类型=&#34;日期&#34;                                     class =&#34; datepicker col s4&#34;名称=&#34;日期&#34;&GT;                             &LT; / DIV&GT;                             &lt; div class =&#34; row right-align&#34;&gt;                         &lt; button class =&#34; wave-effect wave-teal btn-flat&#34;类型=&#34;提交&#34;                             命名=&#34;动作&#34; &GT;                             添加&lt; i class =&#34; material-icons right&#34;&gt; input&lt; / i&gt;                         &LT; /按钮&GT;                     &LT; / DIV&GT;                                 &LT; /形式&GT; ----以下更多形式------ ..... ..... 请注意,我不需要像 &lt; select form =&#34; form1&gt; 因为我需要多个表格的选择值。任何帮助将不胜感激。谢谢!!

1 个答案:

答案 0 :(得分:1)

我使用jQuery在名为title的所有输入中设置值。这会解决你的问题吗?

JS Fiddle

重要的部分:

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