We help IT Professionals succeed at work.
Get Started

Need to have expandable html select dropdown list

levelninesports
on
1,349 Views
Last Modified: 2012-06-27
I have an oscommerce function that turns an array into a dropdown list.. the porblem is sometimes the dropdown list has too many items for most customers to want to choose from.. if there are more than 8 options in the dropdown list I would like the display to show the first 5 and then a "+see all options" which would then expand the list to show them all (and remove the see all options) the list does not need to be collapsable.. this is just convenience its just a dropdown list so it does not get in the way of the page it is just most customers dont need to see so many options

That is if the array holds 6 options for the dropdown list the dropdown list would show them as normal, but if there were 10 the dropdown list would show

1st array data
2nd array data
3rd
4th
5th
+see more options

If they click on one of the 1st 5 its just like a normal selection from a dropdown list, but if they click on the '+see more options' then the list expands to the complete list
1st array data
2nd array data
3rd
4th
5th
6th
7th
8th
9th
10th

like a normal dropdown list
included the relevant code



function tep_draw_pull_down_menu($name, $values) {
    $field = '<select name="' . $name . '">';
    for ($i=0, $n=sizeof($values); $i<$n; $i++) {
      $field .= '<option value="' . ($values[$i]['id'] . '">' . values[$i]['text'] . '</option>';
    }
    $field .= '</select>';
    return $field;
  }
 
 
$name is the name of the <select>field
$values is an array with an 'id' and 'text' for each option to be shown
as you see there is no restriction on the size of this select field if there are 50 options, 50 will be shown

Open in new window

Comment
Watch Question
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 1 Answer and 10 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE