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>
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>
@furqanDev already did that but still won't work, only the 2nd and 3rd option
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 i already did that sir, but still won't work
@username1 What happens when you do? Did you refresh the page?
@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?
@Sinnbeck yes, it says null when i dd(), only 2nd and the 3rd value I can get
@Sinnbeck it is selected by default, but when i try to dd() there's no value, it says null.
@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 Check your database if the first value is set or not.
@Sinnbeck i dd() it in my component in render when filtered it, it will directly to render
<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()
@Sinnbeck in my component render(), beacause that form is for filtered data, it will direclty to render
@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();
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 sign in or create an account to participate in this conversation.