Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

username1's avatar

how to set default value in select option?

good day, I want to get the value in first value in option, but the thing is I can't get the first value, only the 2nd and 3rd value. please help me im just new here thank you.

here is my select option,,,,,

                   <select name="filter_quantity" wire:model.defer="filter_quantity"
                    class="form-control mt-5 col-md-4">                       
                    <option value="1" default>Less Than</option>
                    <option value="2" >Greater Than</option>
                    <option value="3" >Equal to</option>
                    </select>
0 likes
18 replies
furqanDev's avatar

Just add a selected attribute at the option you want to be selected by default.

<select name="filter_quantity" wire:model.defer="filter_quantity" class="form-control mt-5 col-md-4">                       
		<option value="1" selected>Less Than</option>
		<option value="2" >Greater Than</option>
		<option value="3" >Equal to</option>
</select>

Sinnbeck's avatar

The name is selected instead of default

<select name="filter_quantity" wire:model.defer="filter_quantity"
                    class="form-control mt-5 col-md-4">                       
                    <option value="1" selected>Less Than</option>
                    <option value="2" >Greater Than</option>
                    <option value="3" >Equal to</option>
                    </select>
Sinnbeck's avatar

@username1 BTW. What do you mean by

but the thing is I can't get the first value,

Do you mean that it isnt selected by default? Or something else?

username1's avatar

@Sinnbeck it is selected by default, but when i try to dd() there's no value, it says null.

Sinnbeck's avatar

@username1 Where do you dd? Your question was how to get it to have the "Less than" preselected on page load. Instead show the code for how you use the data

username1's avatar

@Sinnbeck i dd() it in my component in render when filtered it, it will directly to render

username1's avatar
                  <select name="filter_quantity" wire:model.defer="filter_quantity"
                    class="form-control mt-5 col-md-4">                       
                    <option value="1" selected>Less Than</option>
                    <option value="2" >Greater Than</option>
                    <option value="3" >Equal to</option>
                    </select>               

still wont work, the value is null when dd()

username1's avatar

@Sinnbeck in my component render(), beacause that form is for filtered data, it will direclty to render

username1's avatar

@Sinnbeck public function render() { dd($this->filter_quantity);

    $qty             = $this->qty;
    $filter_qty      = $this->filter_quantity;

 
        
    $report_data = StockManagement::where(function($query) use ($filter_qty, $qty,){

                                if($filter_qty == 1) {        
                                   $query->where('qty', '<=', $qty);
                                }
                                if($filter_qty == 2) {
                                    $query->where('qty', '>=', $qty);
                                }
                                if($filter_qty == 3) {
                                    $query->where('qty', '=', $qty);
                                }
                              
                                                            
                            })->get();      
username1's avatar

this is from form ,,

                  <select name="filter_quantity" wire:model.defer="filter_quantity"
                    class="form-control mt-5 col-md-4">                       
                    <option value="1" selected>Less Than</option>
                    <option value="2" >Greater Than</option>
                    <option value="3" >Equal to</option>
                    </select>                           
                    <input type="number" name="qty" wire:model.defer="qty"
                    class=" mt-5" style="padding: 8px;">

Please or to participate in this conversation.