prabin19's avatar

How to pass id when selecting value through the list box.

when i click on the list box name should appear but when i click save it on database it id should be insert the id of that name in the list box.

0 likes
6 replies
cviv's avatar

We cannot help by guessing.. :)

Mittensoff's avatar

If you're talking about select boxes, the value you insert into the 'value' attribute is sent through the form and you can access it by referencing the 'name' attribute of the select box.

If that's what you're asking.

Cronix's avatar
<select name="choices">
  <option value="1">First Choice</option>
</select>

as mentioned, the options VALUE is sent with the form.

$request->input('choices') == 1
prabin19's avatar

View

@foreach($suppliers as $key=>$value)
    <input list="supplier" name="supplier">
        <datalist id="supplier">
            <option value="{{$value}}">
        </datalist>
    @endforeach 

Controller

public function create()
{

$suppliers= Supplier::pluck('company_name', 'id');
return view('product.index',compact('suppliers'));
}

tykus's avatar

This should do it:

<input list="supplier" name="supplier">
@foreach($suppliers as $key=>$value)
        <datalist id="supplier">
            <option value="{{$key}}">{{$value}}</option>
        </datalist>
@endforeach 

Please or to participate in this conversation.