Save the value of Dropdown on page reload
<p>JS Experts,</p>

<p>Can anyone provide a solution to this ?</p>

<p>We use DHTMLX and there is a dropdown filter. We use cookies to save the result. When someone filters by First Name, you get the first name list and when you reload, the list remains as First Name list. However, the dropdown shows as blank. </p>

<p>We would like to store the value of the filter in the drop down instead of showing as a blank field(resetting) eg: Filter by First Name > First Name list shown > Reload page > First Name list shown and Dropdown to show First Name.</p>

<p>Ideally a pure javascript solution is needed. Any help is much appreciated.</p>

<pre><code>    HTML Automatically generated by DHTML grid

    &lt;td class=" filter" style="cursor: default;"&gt;&lt;select style="width: 90%;"&gt;&lt;option value=""&gt;&lt;/option&gt;&lt;option value="Recomend"&gt;Recomend&lt;/option&gt;
&lt;option value="Benchmark"&gt;Benchmark &lt;/option&gt;
&lt;option value="Reject"&gt; Reject&lt;/option&gt;
&lt;option value="Age"&gt;Age&lt;/option&gt;
&lt;option value="Transfer"&gt;Transfer &lt;/option&gt;
&lt;/select&gt;&lt;/td&gt;
    &lt;td class=" filter" style="cursor: default;"&gt;
&lt;select style="width: 90%;"&gt;&lt;option value=""&gt;&lt;/option&gt;
&lt;option value="First Name"&gt;First Name&lt;/option&gt;
&lt;option value="Last Name"&gt;Last Name&lt;/option&gt;
&lt;option value="Status"&gt; Status&lt;/option&gt;
&lt;option value="Education"&gt;Education&lt;/option&gt;
&lt;option value="Earning"&gt;Earning&lt;/option&gt;&lt;/select&gt;&lt;/td&gt;

OUR CODE

 mygrid.init();   
    var f_ind=[];
    var f_data=[];
    mygrid.attachEvent("onFilterStart",function(ind,data){
    //alert("Jim "+ mygrid.getFilterElement(6).value);
    setCookie("location_filter",mygrid.getFilterElement(6).value,365);
    setCookie("awaiting_filter",mygrid.getFilterElement(7).value,365);
   return true;
});

/*************/

function getCookie(c_name){
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i&lt;ARRcookies.length;i++){
  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
  x=x.replace(/^\s+|\s+$/g,"");
  if (x==c_name){
    return unescape(y);
    }
  }
}

function setCookie(c_name,value,exdays, secure){
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value + secure; 'path=/';
}

/*****************/

    mygrid.enableHeaderMenu();
    mygrid.enableRowsHover(true,"colourise");
    mygrid.enableColumnMove(true);

    //populate the grid with data by loading the xml file
    xmlstr='&lt;rows&gt;&lt;&lt;@U_AW_DASH_RQH_ACT&amp;S'../'=""&amp;S'''=" "&gt;&gt;&lt;/rows&gt;';
    mygrid.parse(xmlstr, function checkCookie(){
   var first=getCookie("inbox");

   if (first!=null &amp;&amp; first!="")
  {
//alert("Welcome again ");

   mygrid.loadOrderFromCookie();
    mygrid.loadSizeFromCookie();
    mygrid.loadSortingFromCookie();
    mygrid.loadHiddenColumnsFromCookie();
    mygrid.enableAutoSizeSaving();
    mygrid.enableAutoHiddenColumnsSaving();
    mygrid.enableAutoSaving();
    mygrid.enableOrderSaving();
    mygrid.enableSortingSaving();

   var filter_cookie=getCookie("location_filter");
   var filter_cookie2=getCookie("awaiting_filter");

 //alert("Sunit " + filter_cookie);
   if (filter_cookie!=null &amp;&amp; filter_cookie!=""){
  //alert("Brian "+ filter_cookie);
 mygrid.filterBy(6, filter_cookie, true);
}
if (filter_cookie2!=null &amp;&amp; filter_cookie2!="") {
   //alert("Andy "+ filter_cookie2);
   mygrid.filterBy(7, filter_cookie2, true);}
 }
else
{
  //alert("First Visit");
  setCookie("inbox","visited",365);

  mygrid.sortRows(3,"date","des");
  mygrid.setColumnHidden(0,true);
  mygrid.setColumnHidden(1,true);
  mygrid.setColumnHidden(2,true);

    mygrid.enableAutoSizeSaving();
    mygrid.enableAutoHiddenColumnsSaving();
    mygrid.enableAutoSaving();
    mygrid.enableOrderSaving();
    mygrid.enableSortingSaving();

  }
});

checkCookie();
</code></pre>
