Does anybody know how can I set in my select box the first option to empty value?
I'm getting the data from my DB, and I would like to set the option by default as "Please select one option".
Just put "hidden" on option you want to hide on dropdown list.
The select tag in HTML is used to create a dropdown list of options that can be selected. The option tag contains the value that would be used when selected. The default value of the select element can be set by using the 'selected' attribute on the required option. This is a boolean attribute.
</option> , value="" is turned into just value . The value, when set to the empty string is simply discarded.
I found that 'default'=>'Please select'
doesn't work with the HTML5 required attribute. This does work:
$listOfValues = [1 => 'Choice 1']; Form::select('fieldname',[null=>'Please Select'] + $listOfValues);
If you don't like modern PHP syntax,
$listOfValues = array(1 => 'Choice 1'); $listOfValues[null] = 'Please Select'; Form::select('fieldname', $listOfValues);
But the point is to have a label for the null value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With