繁体   English   中英

如何从javascript到jsp获取select选项值

[英]How to get select option value from javascript to jsp

我的 html 有一个选择选项值框,如果我从该框中选择任何选项,我将在 javascript 中获取值,但我希望在 jsp 中使用此值,因为使用此字符串我正在显示从数据库中选择的行,我也尝试过 request.getparameter但没有工作代码:

<script type="text/javascript">
function getAppId()
{
  var value=document.getElementById("planeselect").value;
  document.getElementById("demo").innerHTML="application Id:"+value;

}
</script>

<select id="planeselect" onchange="getAppId()">
        <%
             Set<String> set=appsList.keySet();
            for (String s:set) {
                String appName = (String) appsList.get(s);
        %>
        <option value="<%=s%>"><%=appName%></option>
        <%
            }
        %>
    </select>

在更改时,您可以加载页面并使用request.getParameter()

<script type="text/javascript">
function getAppId()
{
  var value=document.getElementById("planeselect").value;
  document.getElementById("demo").innerHTML="application Id:"+value;
  window.location="URL_of_this_page?RequiredValue="+value;
 }
</script>

<%
     String ValueRequired=request.getParameter("RequiredValue");
     if(ValueRequired!=null){
               *****operation which you want to perform*****
      }
%>  

    <select id="planeselect" onchange="getAppId()">
    <% 
        Set<String> set=appsList.keySet();
        for (String s:set) {
            String appName = (String) appsList.get(s);
    %>
    <option value="<%=s%>"><%=appName%></option>
    <%
        }
    %>
   </select>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM