CFbubu
asked on
Coldfusion + Javascript Question about Lists
Hi Folks,
I have a query below that outputs a list of cities.
<UL id="list">
<cfoutput query="getresults" group="City_ID" >
<LI><a href="somepage.cfm?City_ID =#City_ID# ">#Citynam e#</a></LI >
</cfoutput>
</UL>
[RESULT]
Amstad
Alron
Adderson
Belleview
Banneris
Brentwood
Charstone
Cimbran
..
...
...
Zanker
I am wondering if if were possible to use javascript combined such that the output will look like that below:
[Desired Output]
A
B
C
..
..
Z
The desired output above shows the list like a simple alphabatized list, and when the user clicks on the letter A, the list will 'expand' and will show all the cities starting with 'A' as seen below:
A
Amstad
Alron
Adderson
B
C
D
.
..
Z
I have searched high and low around the internet and saw someone use a javascript code like such below to make an alphabatized list.....but I am not familiar with javascript and cannot seem to get it to work. In addition, I am hoping to make it work as an 'expanding' list as examplified above.
It would be awesome if someone could help me make this a reality! Thanks so much!
[Javascript code below]
var list = { letters: [] }; //object to collect the li elements and a list of initial letters
$("#list").children("li"). each(funct ion(){
var itmLetter = $(this).text().substring(0 ,1).toUppe rCase();
if (!(itmLetter in list)) {
list[itmLetter] = [];
list.letters.push(itmLette r);
}
list[itmLetter].push($(thi s)); //add li element to the letter's array in the list object
});
list.letters.sort(); //sort all available letters to iterate over them
$.each(list.letters, function(i, letter){
list[letter].sort(function (a, b) {
return $(a).text().toUpperCase(). localeComp are($(b).t ext().toUp perCase()) ; //sort li elements of one letter
});
var ul = $("<ul/>"); //create new dom element and add li elements
$.each(list[letter], function(idx, itm){
ul.append(itm);
});
$("#list").append($("<li/> ").append( $("<a/>"). attr("name ", letter.toLowerCase()).addC lass("titl e").html(l etter)).ap pend(ul)); //add the list to a new li and to #list ul
});
I have a query below that outputs a list of cities.
<UL id="list">
<cfoutput query="getresults" group="City_ID" >
<LI><a href="somepage.cfm?City_ID
</cfoutput>
</UL>
[RESULT]
Amstad
Alron
Adderson
Belleview
Banneris
Brentwood
Charstone
Cimbran
..
...
...
Zanker
I am wondering if if were possible to use javascript combined such that the output will look like that below:
[Desired Output]
A
B
C
..
..
Z
The desired output above shows the list like a simple alphabatized list, and when the user clicks on the letter A, the list will 'expand' and will show all the cities starting with 'A' as seen below:
A
Amstad
Alron
Adderson
B
C
D
.
..
Z
I have searched high and low around the internet and saw someone use a javascript code like such below to make an alphabatized list.....but I am not familiar with javascript and cannot seem to get it to work. In addition, I am hoping to make it work as an 'expanding' list as examplified above.
It would be awesome if someone could help me make this a reality! Thanks so much!
[Javascript code below]
var list = { letters: [] }; //object to collect the li elements and a list of initial letters
$("#list").children("li").
var itmLetter = $(this).text().substring(0
if (!(itmLetter in list)) {
list[itmLetter] = [];
list.letters.push(itmLette
}
list[itmLetter].push($(thi
});
list.letters.sort(); //sort all available letters to iterate over them
$.each(list.letters, function(i, letter){
list[letter].sort(function
return $(a).text().toUpperCase().
});
var ul = $("<ul/>"); //create new dom element and add li elements
$.each(list[letter], function(idx, itm){
ul.append(itm);
});
$("#list").append($("<li/>
});
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I wish I could award everyone here who posted solutions all the full award points!
I think all 3 posted solutions were very viable, and I will be implementing all your different suggestions. It will take a little time to decide which would suit my style and purpose best, but I am thrilled at the options given here.
And _agx_ , why does it not surprise me that you are always there to help me out. I wish I had a way to contact you ...and no, I would not harass you with my issues:P I think I have an interesting proposition that may turn up in the near future, and I am hoping that I could tell you more about it...:) Anyways, no worries if you so decide for our contact to remain here. I am just glad to have you around!
Thank you everyone!