View Full Version : Drop down - sort by
youngsc
04-08-2008, 09:54 PM
I'm new to web design and I'm trying find a script that will allow me to add a drop down menu that refines results within a page or subsection of the website. Something like price highest to lowest or vice versa or brand, you've all seen this on larger ecommerece websites before. If you all have any websites or files referencing this I would be very greatful.
Thanks,
Steve
Alright, I just whipped up a little code(if you can't you javascript but you can use php just tell me):
<script type="text/javascript">
var abc = new Array();
var abc = [65,46,32,99,1,"A","k"];
abc.sort(); //sorts the array
document.write('<select>'); // writes our select tag
for (i=0;i<=abc.length-1;i++){ //make a forloop for each value we have in our array
document.write('<option value="i">'+abc[i]+'</option>'); //wirte everything
} //close forloop
document.write('</select>'); //close select tag
</script>
The selected part is an array, if your using an int value, you don't need to the double quotes, otherwise include them.
youngsc
04-08-2008, 10:33 PM
I'm sure this helps but I don't know javascript that well so it just looks foreign to me. Where you put write everything, write what exactly? brand, price, etc.? if so how do I list it? As I said, I just don't know it that well so I'm starting from scratch on creating this part of the website. Is it possible to create this as an external javascript file for each subsection then reference it?
Alrighty:
You put this in every you want to be sorted. Every time you copy and paste this you need to change the variables.
var abc = [65,46,32,99,1,"A","k"];
Is where all your options are, so you need to change those to your needs[more info about this at the bottom of my top post].
Everything else don't worry about it. If you want I'll make a code that'll just get all your selects on the page and make them 123abc order. But that'll take longer. So if you want that just say and I'll make it.
youngsc
04-08-2008, 10:43 PM
If you can do that I would be greatful or if you know of an external site where I can see a full size example that would be great. I know I can put it together I just need to see it in action first then I can understand it all better. thanks much.
Alright, I'll make you the script. It may take over 15 minutes because atm I'm doing something else.
Alrighty, I failed on making this. So just gimme your code so I can change everything that needs to be 123ab- afied.
youngsc
04-08-2008, 11:29 PM
well that's just it I don't have anything yet. I'm in the process of designing and writing the css and html parts. Wasn't sure how to go about this function but thought if I could get a sampling then I could go from there. I tried to take a look at javascript and I started getting a headache. Is there a specific name for that type of function or form? If so I can try searching more from that I just couldn't pull any results when I was looking earlier. Thanks for your help.
I made it up completely by myself, so no. Heres an example though: http://nile.richei.net/applets/array_sort.html
youngsc
04-08-2008, 11:54 PM
That's kinda what I'm looking for and maybe I'm just not familiar enough with it to know if it can be adapted to what I'm looking for.
Here's a link to an example of what I'm looking for exactly: http://www.barbecues.com/web/catalog/ethumbs.aspx?N=103+3187827&Ns=P_Inventory|1||P_ProductName
The section in the center that is a drop down and has "product name" in it. When you select it, it allows you to sort all items within that subsection by price ascending or descending or by brand.
Sorry again for being so clueless on javascript.
So your looking how to display one thing and not the other?
youngsc
04-09-2008, 01:15 AM
to be able to sort them. So if I have products listed across say 2 pages each with different pricing I want a way to be able to sort them ascending or descending based on price. I guess I could set them up ascending to begin with. I don't have to have that capability but I think it would certainly help my site.
Medyman
04-09-2008, 01:21 AM
What are you going to be listing?
It all depends on how the data is brought in. If you'll be hard coding in the values, than you'll have to use javascript. There are tools out there to help. Granted, they're a bit advanced for an outright beginner, but you seem bright enough to pick it up.
If you're bringing things in dynamically -- from a database, for example -- than you should use a server side language. For example, if you're storing products, prices, brands etc... in a MySQL database, it's easy to tell PHP to sort the results accordingly.
With hardcoded values (or to sort things on the client side .. i.e. without having to reload the entire page), I would use something like this (http://tablesorter.com/docs/#Demo).
Hope that helps. :)
youngsc
04-09-2008, 01:53 AM
Thanks I'll take a look through that. Thanks to both of you for the help. I'm trying to write a website from scratch and am teaching myself how as I go along. I don't have much time with a full time job and trying to get licensing in order to start a few businesses on top of this so I don't want anything to advanced, i.e. database linking or programming. thanks again, Steve
Medyman
04-09-2008, 02:10 AM
Thanks I'll take a look through that. Thanks to both of you for the help. I'm trying to write a website from scratch and am teaching myself how as I go along. I don't have much time with a full time job and trying to get licensing in order to start a few businesses on top of this so I don't want anything to advanced, i.e. database linking or programming. thanks again, Steve
Completely understandable.
Though, as a general rule...setting up a database for this kind of application ends up being a time saver in the end.
It does require some technical knowledge to set up though, so obviously not for a beginner.
Just my $0.02
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.