Sign in to follow this  

How do yo retain a selection from a drop down list when refreshing in php

Recommended Posts

This code works but for some reason if you use it in php, it will reload and take you to the top of the page when you make a selection, and I can't use that because is for a long form, and the part where I'm using this is kind of at the bottom, so it would be annoying to the user to have the page reload and take you to the top of the page everytime you make a selection, idk if maybe I could fix this but I have no idea



       <script src="//"></script>
<script src="//"></script>   
      $("#checkAll").on("change", function() {
        $(':checkbox').not(this).prop('checked', this.checked);
     window.onload = function () {
    var cookies = document.cookie,
        sidx = !!cookies ? cookies.match(/myDDIdx=([0-9]+?);?/) : false;
    if (!!sidx && sidx.length >= 2) {
        document.getElementById("Selection").selectedIndex = sidx[1];

document.getElementById("Selection").onchange = function () {
    document.cookie = 'myDDIdx=' + this.selectedIndex + '; path=/;';
    window.location = this.options[[this.selectedIndex]].value;

  <select id="Selection" class="sorter" style="float:right;margin-right:8px;">
    <option value="">Sort by</option>
    <option >Code</option>
    <option value="?orderby=1">Title A-Z</option>
    <option value="?orderby=2">Title Z-A</option>
    <option value="?orderby=3">Brand</option>
    <option value="?orderby=4">Lowest price</option>
    <option value="?orderby=5">Highest price</option>
    <option value="?orderby=6">Lowest Quantity</option>
    <option value="?orderby=7">Highest Quantity</option>

Share this post

Link to post
Share on other sites

Ugh. Why do so many people in web design try to treat web pages like heavy clients?


You are building a web page that will struggle for use on phones, tablets, and older web browsers. Code like that is why I disable scripting on most web pages, and also why businesses end up making dual sites for devices.


Sorry for the complaint rather than constructive answer, just be aware that you are likely losing or annoying 1% to 5% of your potential site users, and also potentially causing the business to invest in a duplicated effort for mobile users because of the choice to make the fancy heavily-scripted pages.

Edited by frob

Share this post

Link to post
Share on other sites
This topic is now closed to further replies.
Sign in to follow this