you have not said how you decide which value to put in the input box?
FIll textfield based on select option
I'm building a form that has a select field with option values that come from the services table.
And I have a text field that I want to to pre-fill it with an value of base_cost that come from the same table.
I'm passing all data to the view (maybe I could pluck only the name and id that I need to build the select box, but for now it works for me).
public function create()
{
$clients = Client::all();
$services = Service::all();
return view('dashboard.jobs.new', compact('clients', 'services'));
}
The view has a select field (works as intended)
<div class="control">
<span class="select is-fullwidth">
<select>
@foreach ($services as $service)
<option value="{{ $service->id }}">{{ $service->name }}</option>
@endforeach
</select>
</span>
</div>
And I have the text field that I wan't a value from the services table, witch one I have no idea how to pass the data to it.
<div class="control">
<input class="input"
name="base_cost" id="base_cost" type="text" value="">
</div>
In short, I've a form that has a select field where the options come from a services table, in the same table there is a base_cost field that I wan't to the value of it to fill a input text in the same form, but the value is based on the selected item from the select box.
What are my options to dynamic fill the base_cost field with the data from services table?
I was thinking that It could be done with ajax, but I never used it before, there is any other way, I don't think vue is an option to me since I know very little of javascript, so if it could be done with ajax, could any one give some directions? Or if I could achieve this without any js would be greate too.
Any help would be welcome!
Please or to participate in this conversation.