retaining select table value after refresh
<p>Basically the code below works just as it should: it refreshes the page base on value of 'rate' and maintains page scroll position after page refresh.</p>

<p>What I am trying to do is add a select table to adjust the rate of refresh, or in other words the value of 'rate'. with my little experience in js I was able to add the select table and set the rate by the selected value, problem is that when the page refreshes the value in the select table defaults to first value in the table, in my case '5'. Second problem is that when i change the value in the table, page scrolls to the top each time a new value is selected. </p>

<pre><code>var rate = 10; // refresh rate    

function refresh() {
    document.cookie = 'scrollTop=' + filterScrollTop();
    document.cookie = 'scrollLeft=' + filterScrollLeft();
    document.location.reload(true);
}

function getCookie(name) {
    var start = document.cookie.indexOf(name + "=");
    var len = start + name.length + 1;

    if (((!start) &amp;&amp; (name != document.cookie.substring(0, name.length))) || start == -1) return null;

    var end = document.cookie.indexOf(";", len);

    if (end == -1) end = document.cookie.length;

    return unescape(document.cookie.substring(len, end));
}

function deleteCookie(name) {
    document.cookie = name + "=" + ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function setupRefresh() {
    var scrollTop = getCookie("scrollTop");
    var scrollLeft = getCookie("scrollLeft");

    if (!isNaN(scrollTop)) {
        document.body.scrollTop = scrollTop;
        document.documentElement.scrollTop = scrollTop;
    }

    if (!isNaN(scrollLeft)) {
        document.body.scrollLeft = scrollLeft;
        document.documentElement.scrollLeft = scrollLeft;
    }

    deleteCookie("scrollTop");
    deleteCookie("scrollLeft");


    setTimeout("refresh()", rate * 1000);
}

function filterResults(win, docEl, body) {
    var result = win ? win : 0;

    if (docEl &amp;&amp; (!result || (result &gt; docEl))) result = docEl;

    return body &amp;&amp; (!result || (result &gt; body)) ? body : result;
}

// Setting the cookie for vertical position


function filterScrollTop() {
    var win = window.pageYOffset ? window.pageYOffset : 0;
    var docEl = document.documentElement ? document.documentElement.scrollTop : 0;
    var body = document.body ? document.body.scrollTop : 0;
    return filterResults(win, docEl, body);
}

// Setting the cookie for horizontal position


function filterScrollLeft() {
    var win = window.pageXOffset ? window.pageXOffset : 0;
    var docEl = document.documentElement ? document.documentElement.scrollLeft : 0;
    var body = document.body ? document.body.scrollLeft : 0;
    return filterResults(win, docEl, body);
}​
</code></pre>

<p>I did not include my attempt at it but I can included it if need be, basically I am just looking for the right way to go about it,</p>

<p>thanks</p>
