Jump to content

Alphabetized dropdown menu


fazlionline

Recommended Posts

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 by monkeysaurus
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...