Văn Lộc Văn Lộc - 1 month ago 18
PHP Question

How to hide any item in select > option dropdown?

Today, I have two question with my problem.

First question:

I was using the loop to

foreach
an array.

I only get two option with having values.

Like this:

<select>
<option disable> Angust </option>
<option disable> October </option>
<option values="20"> Noel </option>
<option disable> November </option>
<option disable> December </option>
<option values="34"> Happy new year </option>
</select>


And have any method to hidden all option with an attribute is
disable
, exception option have attribute
values
.

Second question:

So, when I tried to loop table
special_month
table, I want to get only
<option>
have
values
.

And when to selected a
<option>
, I also get values and get the name of this item selected using method
POST
.

Ex:

I selected:

<option values="34"> Happy new year </option>
.

So, I want get
id
with
values = 34
and get
name
with
values = Happy new year
.

Answer
  1. It should be disabled and not disable (missing the d in the end)
  2. It should be value and not values (the s in the end shouldn't be there)
  3. If you want you can use css to hide the disabled options:

#s2 option[disabled] {
  display: none;
}
<select id="s1">
   <option disabled="disabled">     Angust      </option>
   <option disabled="disabled">     October     </option>
   <option value="20"> Noel        </option>
   <option disabled="disabled">     November    </option>
   <option disabled="disabled">     December    </option>
   <option value="34"> Happy new year </option>
</select>
<br /><br />
<select id="s2">
   <option disabled="disabled">     Angust      </option>
   <option disabled="disabled">     October     </option>
   <option value="20"> Noel        </option>
   <option disabled="disabled">     November    </option>
   <option disabled="disabled">     December    </option>
   <option value="34"> Happy new year </option>
</select>

Comments