如何保持Dropdownlist值相同刷新页面后 [英] How to keep Dropdownlist value same after refresh the page

查看:259
本文介绍了如何保持Dropdownlist值相同刷新页面后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个下拉列表

<select name="cate">
  <option value="h">India</option>
  <option value="m">USA</option>
  <option value="c">England</option>
</select>
<input type="submit" value="show">

点击显示按钮时,下表将显示所选国家/地区的详细信息。
详细信息来自数据库,每次点击页面都会刷新。

While clicking on show button,in the below table it will show the selected country details. Details are coming from database,and each click the page will refresh.

我的问题是,如果用户选择英格兰在下拉列表中,按钮,它将显示详细信息,但下拉列表将仅显示名字。
我想显示所选的值名称。

My problem is that, if a user selects England on Dropdown list and clicks on show button, it will show the details, but the dropdown list will show the first name only. I want to show the selected value name.

请帮助我。

推荐答案

<input type="hidden" name="selectedValue" value="0"/>  

将上面的一个放在选择标签的下面

put the above one in just below of your select tag

并在您的servlet中执行此操作

and do this in your servlet

String selectedValue = `request.getParameter("selectedValue")` 

现在将selectedValue设置为servlet请求

now set the selectedValue into the servlet request

在你最后的jsp中创建一个JS函数

create a JS function in your final jsp

function selectedValue(){  

    var value =<%=request.getParameter("selectedValue")%>;  
    if(value !=null)  
        {

        document.f1.slvalue.selectedIndex=value ;          

        }    

} 

调用selectedValue ()函数在你的最后的jsp页面的bodyload。
slvalue是您选择的标签的名称

call the selectedValue() function on bodyload of your final jsp page. "slvalue" is a name of your select tag

这篇关于如何保持Dropdownlist值相同刷新页面后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆