We are looking to increment the <option>
within a <select>
input type. If the option value $AccountExecutive->COMMISSION_RATE
is $Rate
, the <option>
should be selected.
I should note that $AccountExecutive->COMMISSION_RATE
is a decimal (0.5000).
We have successfully done this in standard PHP but we would like it to stay in Laravel.
<div class="form-group">
<label for="AE_COMMISSION_RATE">Commission Rate</label>
<select class="form-control" id="AE_COMMISSION_RATE" name="AE_COMMISSION_RATE">
<option value="0">Please enter a Value..</option>
@for($Rates = .05; $Rates < 1.05; $Rates += .05)
@if($AccountExecutive->COMMISSION_RATE == $Rates)
<option value="{{ $Rates }}" selected>{{ $Rates * 100 }}% </option>
@else
<option value="{{ $Rates }}">{{ $Rates * 100 }}%</option>
@endif
@endfor
</select>
</div>
Just work with integers. Let $Rates
is a percent value, not fractional.
<div class="form-group">
<label for="AE_COMMISSION_RATE">Commission Rate</label>
<select class="form-control" id="AE_COMMISSION_RATE" name="AE_COMMISSION_RATE">
<option value="0">Please enter a Value..</option>
@for($Rates = 5; $Rates < 105; $Rates += 5)
@if(intval($AccountExecutive->COMMISSION_RATE * 100) === $Rates)
<option value="{{ $Rates / 100 }}" selected>{{ $Rates }}% </option>
@else
<option value="{{ $Rates / 100 }}">{{ $Rates }}%</option>
@endif
@endfor
</select>
</div>