I would like to get the option value from a HTML select tag and pass it into a PHP variable.
I am able to do this in a JavaScript function, however, I would like to use this variable elsewhere in the script.
This is the select tag code:
<select id="languageselector" onChange='showSelected(this.value)'>
<option value="">Pick A language</option>
@foreach($reviewForm_language as $lang)
<option value="{{$lang->id}}">{{$lang->name}}</option>
@endforeach
</select>
This is the JavaScript code to get the selected value;
<script type="text/javascript">
function showSelected(val)
{
document.getElementById('selectedResult').innerHTML = val;
return val
}
</script>
To display the selected value I call and works well as required.
<div id='selectedResult'></div>
I would like to pass this answer <div id='selectedResult'></div>
to a PHP variable in the same page without reloading.
Anyone assist, thank you.