HighDots Forums  

Sorting on drop down boxes ?

Macromedia Dreamweaver Macromedia Dreamweaver Discussions (macromedia.dreamweaver)


Discuss Sorting on drop down boxes ? in the Macromedia Dreamweaver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
VegaLA
 
Posts: n/a

Default Sorting on drop down boxes ? - 11-10-2004 , 06:26 PM






Hi all, I have a drop down box that lists data from adatabase and it
works well but I would like the data to be sorted on alpha. I could change the
datasource to look at a view that is alpha sorted but i'd like to know if there
is a way to do this in DWMX ? Any ideas ? Mitch...


Reply With Quote
  #2  
Old   
Mick White
 
Posts: n/a

Default Re: Sorting on drop down boxes ? - 11-10-2004 , 07:29 PM






VegaLA wrote:

Quote:
Hi all, I have a drop down box that lists data from adatabase and it
works well but I would like the data to be sorted on alpha. I could change the
datasource to look at a view that is alpha sorted but i'd like to know if there
is a way to do this in DWMX ? Any ideas ? Mitch...

Demo: http://mickweb.com/javascript/demo/sortMenu.html

You can do using javascript, the following sorts the labels(text):

<script type="text/JavaScript">
function sortMenuAlpha(x,y){
A=x[0];B=y[0];
return A>B?1:A<B?-1:0

}

function alphaMenu(menu,headerInPlace){
t=headerInPlace?+1:+0,a=new Array();
for(var i=t;i<menu.length;i++){
a[a.length]=[menu.options[i].text,menu.options[i].value]
}
a.sort(sortMenuAlpha);
menu.options.length=t
for(var j=t,k=0;j<=a.length;j++){
menu.options[j]=new Option(a[k][0],a[k][1])
k++
}
}
</script>
<body onload="alphaMenu(document.forms[0].mu,true)">

<form action="" method="get">
<select name="mu">
<option value="Select" selected>Select</option>
<option value="pet">cat</option>
<option value="anteater">aardvark</option>
<option value="caver">bat</option>
<option value="meat">chicken</option>
<option value="insect">ant</option>
<option value="predator">bear</option>
</select>

</form>

Mick


Reply With Quote
  #3  
Old   
Murray *TMM*
 
Posts: n/a

Default Re: Sorting on drop down boxes ? - 11-10-2004 , 07:34 PM



But it'd be better to do it in the recordset.

--
Murray --- ICQ 71997575
Team Macromedia Volunteer for Dreamweaver
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================

"Mick White" <mwhite13BOGUS (AT) rochester (DOT) rr.com> wrote

Quote:
VegaLA wrote:

Hi all, I have a drop down box that lists data from adatabase and
it works well but I would like the data to be sorted on alpha. I could
change the datasource to look at a view that is alpha sorted but i'd like
to know if there is a way to do this in DWMX ? Any ideas ? Mitch...

Demo: http://mickweb.com/javascript/demo/sortMenu.html

You can do using javascript, the following sorts the labels(text):

script type="text/JavaScript"
function sortMenuAlpha(x,y){
A=x[0];B=y[0];
return A>B?1:A<B?-1:0

}

function alphaMenu(menu,headerInPlace){
t=headerInPlace?+1:+0,a=new Array();
for(var i=t;i<menu.length;i++){
a[a.length]=[menu.options[i].text,menu.options[i].value]
}
a.sort(sortMenuAlpha);
menu.options.length=t
for(var j=t,k=0;j<=a.length;j++){
menu.options[j]=new Option(a[k][0],a[k][1])
k++
}
}
/script
body onload="alphaMenu(document.forms[0].mu,true)"

form action="" method="get"
select name="mu"
option value="Select" selected>Select</option
option value="pet">cat</option
option value="anteater">aardvark</option
option value="caver">bat</option
option value="meat">chicken</option
option value="insect">ant</option
option value="predator">bear</option
/select

/form

Mick



Reply With Quote
  #4  
Old   
MillaReallywasabithc
 
Posts: n/a

Default Re: Sorting on drop down boxes ? - 11-10-2004 , 07:50 PM



i am posting here as part of an assingment for a multimedia course i am going
i have to copy a reply into my assingnment
if some one would be kind enough to reply i would be much obliged.

Reply With Quote
  #5  
Old   
Murray *TMM*
 
Posts: n/a

Default Re: Sorting on drop down boxes ? - 11-10-2004 , 07:51 PM



bithc? You need a spellchecker! 8)

--
Murray --- ICQ 71997575
Team Macromedia Volunteer for Dreamweaver
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================

"MillaReallywasabithc" <webforumsuser (AT) macromedia (DOT) com> wrote

Quote:
i am posting here as part of an assingment for a multimedia course i am
going
i have to copy a reply into my assingnment
if some one would be kind enough to reply i would be much obliged.



Reply With Quote
  #6  
Old   
David Young
 
Posts: n/a

Default Re: Sorting on drop down boxes ? - 11-10-2004 , 08:13 PM



I agree. It's too easy to sort the data in the recordset, and then simply
write the options out in a loop. It requires all of 3 lines of code after
the ORDER BY command is used in the select statement. It's better to let
the server order the recordset than to use client-side resources to simply
sort a listbox.


--
David Young
Senior Web Designer
CFWebmasters.com
david (AT) cfwebmasters (DOT) com
"Murray *TMM*" <forums (AT) HAHAgreat-web-sights (DOT) com> wrote

Quote:
But it'd be better to do it in the recordset.

--
Murray --- ICQ 71997575
Team Macromedia Volunteer for Dreamweaver
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================

"Mick White" <mwhite13BOGUS (AT) rochester (DOT) rr.com> wrote in message
news:cmubpq$jh7$1 (AT) forums (DOT) macromedia.com...
VegaLA wrote:

Hi all, I have a drop down box that lists data from adatabase and
it works well but I would like the data to be sorted on alpha. I could
change the datasource to look at a view that is alpha sorted but i'd
like
to know if there is a way to do this in DWMX ? Any ideas ? Mitch...

Demo: http://mickweb.com/javascript/demo/sortMenu.html

You can do using javascript, the following sorts the labels(text):

script type="text/JavaScript"
function sortMenuAlpha(x,y){
A=x[0];B=y[0];
return A>B?1:A<B?-1:0

}

function alphaMenu(menu,headerInPlace){
t=headerInPlace?+1:+0,a=new Array();
for(var i=t;i<menu.length;i++){
a[a.length]=[menu.options[i].text,menu.options[i].value]
}
a.sort(sortMenuAlpha);
menu.options.length=t
for(var j=t,k=0;j<=a.length;j++){
menu.options[j]=new Option(a[k][0],a[k][1])
k++
}
}
/script
body onload="alphaMenu(document.forms[0].mu,true)"

form action="" method="get"
select name="mu"
option value="Select" selected>Select</option
option value="pet">cat</option
option value="anteater">aardvark</option
option value="caver">bat</option
option value="meat">chicken</option
option value="insect">ant</option
option value="predator">bear</option
/select

/form

Mick





Reply With Quote
  #7  
Old   
Mick White
 
Posts: n/a

Default Re: Sorting on drop down boxes ? - 11-10-2004 , 09:12 PM



David Young wrote:

Quote:
I agree. It's too easy to sort the data in the recordset, and then simply
write the options out in a loop. It requires all of 3 lines of code after
the ORDER BY command is used in the select statement. It's better to let
the server order the recordset than to use client-side resources to simply
sort a listbox.


It's easy using JS, too.
Mick


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.