Maximus1
1 week ago
132
7
Laravel

How to get a value based on a selected variable in an array

Posted 1 week ago by Maximus1

I want to get and display the corresponding value of a selected variable in an array. I think did okay with the code but it is bringing no result. This value should be inputed automatically in the priceamount field when the corresponding fee type is selected.

BLADE-VIEW

<div>
<td width="40%"><select name="fee_type[]" class="form-control select2" required>
                    <option value="">{{_lang('Select One') }}</option>
                    {{ create_option('fee_types','id','fee_type',old('fee_id')) }}
                </select></td>                  
                    <td><input type="text" class="form-control float-field priceamount" name="priceamount[]"value="0" required></td>
</div>

<script type="text/javascript">
$('select[name=fee_type]').on('change',function(){
            var _token=$('input[name=_token]').val();
            var fee_id = $('select[name=fee_type]').val();
            $.ajax({
                type: "POST",
                url: "{{url('prices/fee_amount')}}",
                data:{_token:_token,fee_id:fee_id},
                success: function(data){
                    $('input[name=priceamount]').val(data);             
                }
            });
        }); 
</script>

CONTROLLER

 public function get_fee_amount(Request $request)
                              {
                           $feetype = FeeType::find($request->fee_id)->priceamount;
                           return $feetype;
                               }    

Now i am trying to get the corresponding priceamount from the fee_type selected but without success. It still does not show or get the priceamount value. Can anyone please help?

Please sign in or create an account to participate in this conversation.