fazlionline Posted March 15, 2009 Report Share Posted March 15, 2009 Can I alphabetize a drop down menu, which have more than 100 values.. Quote Link to comment Share on other sites More sharing options...
Andrea Posted March 15, 2009 Report Share Posted March 15, 2009 Of course you can. Quote Link to comment Share on other sites More sharing options...
fazlionline Posted March 15, 2009 Author Report Share Posted March 15, 2009 but how can i do it. Quote Link to comment Share on other sites More sharing options...
PicnicTutorials Posted March 15, 2009 Report Share Posted March 15, 2009 a b c d e f g h i j k l m n o p q r s t u v w x y z Quote Link to comment Share on other sites More sharing options...
fazlionline Posted March 15, 2009 Author Report Share Posted March 15, 2009 sorry Eric they are more than 100 and i want to do it with a script or any code because i will add more options to it. Quote Link to comment Share on other sites More sharing options...
PicnicTutorials Posted March 15, 2009 Report Share Posted March 15, 2009 sorry Ericthey are more than 100 and i want to do it with a script or any code because i will add more options to it. You'll need JS for that. Google "javascript alphabetize" Quote Link to comment Share on other sites More sharing options...
monkeysaurus Posted March 15, 2009 Report Share Posted March 15, 2009 (edited) Or a server side language. For example... PHP: <?php $options = array('John', 'Eric', 'Thelma'); // and 97 others sort($options); ?> <?php foreach($options as $k=>$v){ ?> <?php echo $v?> <?php } ?> Python: options = ["John", "Eric", "Thelma"] options.sort() # Gives you a sorted list, then do your HTML thing as above This could be done in javascript, but I wouldn't recommend it. Javascript might be switched off, and if you're injecting 100 elements into the DOM, that would be awfully slow. The best way to do it would be to put all 100 elements into an array, sort it, build the HTML in a string, then inject the string into the select list's innerHTML. But really, server side is the way to go. Edited March 15, 2009 by monkeysaurus Quote Link to comment Share on other sites More sharing options...
jlhaslip Posted March 15, 2009 Report Share Posted March 15, 2009 javascript solution can be found here: http://w3schools.invisionzone.com/index.php?s=&showtopic=23866&view=findpost&p=131860 Take your pick. Quote Link to comment Share on other sites More sharing options...
fazlionline Posted March 16, 2009 Author Report Share Posted March 16, 2009 hi i like this code <?php $options = array('John', 'Eric', 'Thelma'); // and 97 others sort($options); ?> <?php foreach($options as $k=>$v){ ?> <?php echo $v?> <?php } ?> but forexaple if i have Goolge how can i write the values in PHP as you wrote: $options = array('John', 'Eric', 'Thelma'); // and 97 others sort($options); if i change this to $options = array('Google', 'Yahoo', 'Hotmail'); // and 97 others sort($options); where can i write it links, for exampel, for the above code: http://www.google.com http://www.yahoo.com http://www.hotmail.com thanks Quote Link to comment Share on other sites More sharing options...
monkeysaurus Posted March 16, 2009 Report Share Posted March 16, 2009 Use an associative array, and asort instead of sort: <?php $options = array('http://google.com'=>'Google', 'http://www.yahoo.com'=>'Yahoo', 'http://www.hotmail.com'=>'Hotmail'); asort($options); ?> <?php foreach($options as $k=>$v){ ?> <?php echo $v?> <?php } ?> Quote Link to comment Share on other sites More sharing options...
fazlionline Posted March 16, 2009 Author Report Share Posted March 16, 2009 (edited) <?php$options = array('http://google.com'=>'Google', 'http://www.yahoo.com'=>'Yahoo', 'http://www.hotmail.com'=>'Hotmail'); asort($options);?><?php foreach($options as $k=>$v){ ?><?php echo $v?><?php } ?> Edited April 21, 2009 by fazlionline Quote Link to comment Share on other sites More sharing options...
monkeysaurus Posted March 16, 2009 Report Share Posted March 16, 2009 Just change the extension of the file to .php, that should do the trick if you have PHP on your server. Quote Link to comment Share on other sites More sharing options...
fazlionline Posted March 16, 2009 Author Report Share Posted March 16, 2009 (edited) thanks dear it is working now but i can not follow the link click on any option, nothing will happen... Edited April 21, 2009 by fazlionline Quote Link to comment Share on other sites More sharing options...
jlhaslip Posted March 16, 2009 Report Share Posted March 16, 2009 http://www.faqs.org/docs/htmltut/forms/_SELECT_onChange.html Quote Link to comment Share on other sites More sharing options...
fazlionline Posted March 16, 2009 Author Report Share Posted March 16, 2009 <?php$options = array('http://google.com'=>'Google', 'http://www.yahoo.com'=>'Yahoo', 'http://www.hotmail.com'=>'Hotmail'); asort($options);?><?php foreach($options as $k=>$v){ ?><?php echo $v?><?php } ?> Quote Link to comment Share on other sites More sharing options...
jlhaslip Posted March 16, 2009 Report Share Posted March 16, 2009 (edited) What is it doing (or not doing) 'properly'? Works fine for me. Google, then Hotmail, then Yahoo! in a drop-down select box. Did you add a Submit button to the Form? Edited March 16, 2009 by jlhaslip Quote Link to comment Share on other sites More sharing options...
monkeysaurus Posted March 16, 2009 Report Share Posted March 16, 2009 jhlaslip's solution (http://www.killersites.com/forums/post/5232/#p5232) should work perfectly, if you add it to the code that you already have. Quote Link to comment Share on other sites More sharing options...
fazlionline Posted March 23, 2009 Author Report Share Posted March 23, 2009 (edited) Google Hotmail Yahoo Edited April 21, 2009 by fazlionline Quote Link to comment Share on other sites More sharing options...
jlhaslip Posted March 23, 2009 Report Share Posted March 23, 2009 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.