Jump to content

Sorting with links


Agent Moose

Recommended Posts

You'd have to loop through all of the names. While in the loop, substring the first letter of the current name out. Check if it is the letter you're trying to sort. If it is, add it to an array.At the end of the loop, just display all of the array elements. :)

Link to comment
Share on other sites

1st person who posted* I am a bit confused by yours. Do you think you can just give me an example of one or two letters?2nd person who posted* I am not looking for something like that. I am look so that when you click on a letter, whatever letter you click on it will sort those ones...I guess I will have to make an exra page to do it though...EDIT: Here is a link to what i want to be sorted...it is a radio code I made...click here

Link to comment
Share on other sites

Here:

<script type="text/javascript">function sort(let) {  x=[]; //This array contains all of the words.  y=[]; //This will, at the end of the script, contain all words beginning with the variable let out of the array x.  x[0]="hello" //Element num 1...  x[1]="helo" //num 2...  x[2]="ff" //num 3...  for(i=0;i<x.length;i++) { //Looping through the array...	if(x[i].substr(0,1).toLowerCase()==let) { //This checks if the letter at space 1 in the string is equal to the let...	  y[y.length]=x[i]; //If so, add it to the y variable...	}  }  return y; //Send y to whoever's calling this thing...}</script>

Basically, now if you do this:x=sort("a");The variable x, now an array, will contain all of the array elements that start with a. Is that what you'd like? :)

Link to comment
Share on other sites

You just add more things to the array. For example, if I also wanted to add the words "lol", "hel", and "choc", I'd do this:

<script type="text/javascript">function sort(let) { x=[]; //This array contains all of the words. y=[]; //This will, at the end of the script, contain all words beginning with the variable let out of the array x. x[0]="hello" //Element num 1... x[1]="helo" //num 2... x[2]="ff" //num 3... x[3]="lol"; x[4]="hel"; x[5]="choc"; for(i=0;i<x.length;i++) { //Looping through the array... if(x.substr(0,1).toLowerCase()==let) { //This checks if the letter at space 1 in the string is equal to the let... y[y.length]=x; //If so, add it to the y variable... } } return y; //Send y to whoever's calling this thing...}</script>
See? :)Now if we do this underneath:alert(sort("h"));It'll alert this:
hello,helo,hel
:)
Link to comment
Share on other sites

So you want it in that format? So that you could do something like this:x[0]=["radio station link","radio station name","radio station description","genre"]And it'll replace the current tables with only the ones thats' stations start with the letter you choose?I can change the code so it does that. :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...