I know its the easiest question but cant get the correct answer
<div class="col-12 col-md-4 col-lg-5 mt10-xs">
<p>Status</p>
<div class="form-group FL mr20 w100-xs">
<div class="rsi-custom-select">
<select class="form-control" id="statustab_{{ $row['placementkey'] }}" class="select2-selecting" onchange="listingByStatus(this,'{{ $row['placementkey'] }}')">
@foreach($placementStatus as $pl)
<option @if($pl['placement_status_id'] == $row['statusid'] ) selected @endif value="{{$pl['placement_status_key']}}">{{$pl['placement_status']}}</option>
@endforeach
</select>
</div>
</div>
</div>
This is my onchange
function. In this How Can I get the previous Selected Value from my select box
function listingByStatus(ths,key){
var thisSelect = $('#statustab_'+key).text();
var statusText = $( "#statustab_"+key+" option:selected" ).text();
var currentval = $( "#statustab_"+key+" option:selected" ).val();
}
You could include a hidden input field on your page
Then in your script you could access as any other input:
Set it after an onchange event occurs:
Save the original value using
data()
when the element gets focus:And then get the saved old value in your
onchange
function:Try below code. Hope it will help you.
data-*
to store the old valuedata-*
as the old value and the selected option as new valueCombine the
focus
event with the change event to achieve what you want:Try like this:
This will give you the last value which is selected.
Hope this helps you!