Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


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


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • This topic is locked This topic is locked
2 replies to this topic

#1 Brainx7   Members   -  Reputation: 134

Like
0Likes
Like

Posted 27 June 2014 - 04:26 PM

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

 

<!DOCTYPE HTML>
<html>
  <head>
   

       <script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>   
    <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;
};
      
      </script>

  <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>
</select>



Sponsor:

#2 frob   Moderators   -  Reputation: 30552

Like
0Likes
Like

Posted 27 June 2014 - 04:44 PM

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, 27 June 2014 - 04:45 PM.

Check out my book, Game Development with Unity, aimed at beginners who want to build fun games fast.

Also check out my personal website at bryanwagstaff.com, where I write about assorted stuff.


#3 Madhed   Crossbones+   -  Reputation: 3653

Like
0Likes
Like

Posted 27 June 2014 - 04:56 PM

You should do the sorting via ajax or if the whole list is available, sort on the client side completely.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS