troubleshooting Question

How Do I Hide the first option in a select box?

Avatar of Member_2_7966984
Member_2_7966984 asked on
4 Comments1 Solution7 ViewsLast Modified:

I have a drop down menu using the select element of terms from various custom taxonomies - The drop down list are dynamically generated using this code. here is an example of one of them :

<div class="hp-dd-menu"> <!-- Machine Make Drop Down -->
<?php   $categories = get_categories('taxonomy=machine-make');   $select = "<select name='cat' id='cat1' class='postform'>n";   $select.= "<option value='-1'>MAKE</option>n";     foreach($categories as $category){         if($category->count > 0){                 $select.= "<option value='".$category->slug."'>".$category->name."</option>";         }   }     $select.= "</select>";   echo $select; ?> <script type="text/javascript">     var cat1dropdown = document.getElementById("cat1");     function onCat1Change() {                 if ( cat1dropdown.options[cat1dropdown.selectedIndex].value != -1 ) {                         location.href = "<?php echo home_url();?>/machine-make/"+cat1dropdown.options[cat1dropdown.selectedIndex].value+"/";                 }     }     cat1dropdown.onchange = onCat1Change; </script> </div>

I am noticing that the first option in the select drop down menu is also appearing so it looks as though the word appears two times in a row... HEre is a dev ink to the site I am working on to preview what I am describing

(See red drop down menus about halfway down on the home page) 

So I am wondering if there was any way I could remove the first option when the dropdown menu is triggered somehow?

Screenshot -


Ron Malmstead
Network Operations Manager

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros