Avatar of Member_2_7966984
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 https://imsparts.wpengine.com/

(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 - https://snipboard.io/TPAcCU.jpg



 

WordPressPHPJavaScript

Avatar of undefined
Last Comment
Ron Malmstead

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Ron Malmstead

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Member_2_7966984

ASKER
Ah I see - Never Mind I was able to make it work with your suggestion - Thanks!
Ron Malmstead

 You could use JQuery..

$("#my-drop-down-select-element-id").find("option").eq(0).remove();

Open in new window

https://stackoverflow.com/questions/26785655/hide-first-option-in-select
Ron Malmstead

Cheers.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck