Link to home
Start Free TrialLog in
Avatar of Member_2_7966984

asked on

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

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>

Open in new window

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 -


Avatar of Ron Malmstead
Ron Malmstead
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Member_2_7966984


Ah I see - Never Mind I was able to make it work with your suggestion - Thanks!
 You could use JQuery..


Open in new window