将会话值设置为jsp中的下拉列表 [英] set session value to dropdown in jsp

查看:100
本文介绍了将会话值设置为jsp中的下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在javascript中从数组中获取下拉值。它会在页面加载时填充。使用编辑选项时出现问题。当页面加载时,我必须在下拉列表中选择一个特定值(保存在数据库中的值)。我尝试使用会话变量,但我无法通过会话在html中设置下拉列表的选定值。

请帮助我卡住。

提前感谢:)

i get the drop down values from array in javascript. It gets populated on page load. the problem comes while using the edit option. I have to select a particular value in dropdown(the one saved in database) when the page gets load. i tried it using session variable but i am not able to set the selected value of dropdown in html through session.
please help i am stuck.
thanks in advance :)

推荐答案

我自己设法解决了一些问题:)



Some how I managed to solve it myself :)

<![CDATA[<%
int session_val = (Integer)session.getAttribute("case_type");%>]]> 







function addOption(selectbox,text,value )
{
	var optn = document.createElement("OPTION");
	optn.text = text;
	optn.value = value;
	selectbox.options.add(optn);
}

function addOption_list(){
	 objcasesubtype =  document.getElementById("case_subtype");
	 var session_sub= '<%=session_subtype%>';
	 
    	 casesubtype = new Array("Bail Application","Anticipatory Bail Application","Criminal Appeal","Acquittal Appeal","Transfer Petition");
     
	objcasesubtype.options.length = 0;
		
		 
for (var i=0; i < casesubtype.length;++i){
	addOption(document.addcase.case_subtype, casesubtype[i], casesubtype[i]);}

for(var x=0;x <=objcasesubtype.length ; x++)
{
   if(session_sub == objcasesubtype.options[x].value)
	   objcasesubtype.selectedIndex = x;
};


这篇关于将会话值设置为jsp中的下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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