aspose file tools*
The moose likes JSP and the fly likes How to retain the value of drop down on click of browser back button Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "How to retain the value of drop down on click of browser back button" Watch "How to retain the value of drop down on click of browser back button" New topic
Author

How to retain the value of drop down on click of browser back button

soni lal
Greenhorn

Joined: Jan 31, 2011
Posts: 26
Hi,

I am facing one problem while coming back on clcik of browser back button:

In my application I have 2 drop downs.
1st Drop down : This is getting populated in jsp itself .
code :
<select id="archiveTypeFilter">
<option value="archive_false"><IM:get.localized.text localeCode="<%=strUILocale%>" key="SEARCH.ARCHIVE_OFF" /></option>
<option value="archive_true"><IM:get.localized.text localeCode="<%=strUILocale%>" key="SEARCH.ARCHIVE_ON" /></option>
</select>

2nd drop down : This is getting populated from a db call in javascript file.

After following steps:
Step 1 : Select some value in both drop down
Step 2 : Click on a hyperlink on the page and control will take you to next page
Step 3: Click on browser back button , It will take you to previous page

The problem occurs :
In this page the 1st drop down is retaining the selected value but the 2nd drop down is not retaining the selected value.



I have to retain the selected value of both drop downs.

Please anyone help.
Thanks in advance!!
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1398
    
    6

Second drop down won't, because every time the page is loaded it's populated with dynamic values. So may be you could somehow store the selected index from the 2nd drop down, when the user navigates to the next page hyperlink, now when you are back the previous page retrieve the stored index and use that. Could you show the code how you are populating the 2nd drop down?


Swastik
soni lal
Greenhorn

Joined: Jan 31, 2011
Posts: 26
Thanks !!

this is the drop down in jsp :
<select id="documentTypeFilter">
</select>

this is getting populated in JS function (populateDropDown) where dropDownElem is documentTypeFilter. This function is getting called by initialize method of the same JS.

The function as below:

'populateDropDown':function(dropDownElem,sourceElem,defaultSelection){

//alert("dropDownElem.length::"+dropDownElem.length);
var itms = sourceElem.select('li a');
//alert("itms.length::"+itms.length);
dropDownElem.options.length = 0;
for(var i=dropDownElem.length;i>=0;i--){
dropDownElem.options[i] = null;
}
for(var i=0;i<itms.length;i++){
var elementId = itms[i].getAttribute('id');
var displayName = itms[i].innerHTML;
var l = dropDownElem.options.length;

dropDownElem.options[l] = new Option(displayName, elementId, (elementId==defaultSelection));
console.log(elementId);console.log(defaultSelection);
if (elementId==defaultSelection){
dropDownElem.selectedIndex = l;
}
}
},

Please let me know if it is not clear.

Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1398
    
    6

This is not exactly your code, but you may apply logic somewhat like this
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to retain the value of drop down on click of browser back button
 
Similar Threads
Drop down box issue
Dynamic values for JSF selectOneMenu using javascrpt. JSF validation error.
How to retain the selected values in the drop down on submit
How to retain value in struts 2 using <s:select></s:select> tag
Using html drop down box to retain values (in a jsp page)