0

I have a Payments table, which has 3 fields (id, item, amount) with the following query, with which I fill a combobox with all items, now I want to make that every time I select an item, the amount is automatically filled in an imput that I have in the form.

<div class="form-group">
    <label class="col-sm-2 control-label" for="Old">Tipo de pago* </label>
    <div class="col-sm-10">
        <select  class="form-control" id="pagos" name="pagos" >
        <option value="" >Selecciona pago</option>
        <?php
        $sql = "select id, rubro, monto from pagos";
        $q = $conn->query($sql);
        
        while($r = $q->fetch_assoc())
        {
        echo '<option value="'.$r['id'].'"  '.(($pagos==$r['id'])?'selected="selected"':'').'>'.$r['rubro'].'</option>';
        }
        
        ?>                                  
        
        </select>
    </div>
</div>
Dharman
  • 30,962
  • 25
  • 85
  • 135
  • Hi, you can use ajax for that . Here are some [examples](https://stackoverflow.com/questions/42107672/dropdown-onchange-calling-php-function) . – Swati Dec 19 '20 at 04:09

1 Answers1

1

If I understood what you want, you could use jQuery to do that:

  • Let's suppose you have you have an Input:text with the id="MyInput"
$('#pagos').change(function() {

  $('#MyInput').val($('#pagos').val());

})