Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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 :)
Posted

1 solution

Some how I managed to solve it myself :)

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


Java
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;
};
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900