Now I'm working with Laravel 5.
I got value from select option like below:
select name="billing_provider" onChange="changeLanguage(this.value)"> @foreach($tests as $test)
option value="{{ $test->tax_id }},{{ $test->npi }}" name="billing_provider">
{{ $test->test_name }} </option>@endforeach </select>
Here I need to explode the option value and store it into another text field value.
How can I do that?
First, you have made a mistake building your HTML.
<select>
has an attributename
which is going to be the key in the global arrays$_GET
or$_POST
. However<option>
doesn't have attributename
. You should remove that.If you want to separate the value of
billing_provider
in your backend (php /w Laravel), do so. In your method which handles the submission of the form:Or if you want to perform this action before form submission and you're using jQuery, then you can do this: https://jsfiddle.net/17fkpqbe/
JavaScript (/w jQuery):
HTML: