This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
soni lal
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1603
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
soni lal
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1603
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is not exactly your code, but you may apply logic somewhat like this
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic