fill input with select value in jquery

2

I'm trying to populate a value dynamically with jquery:

In case I want to put the value of the plan value when selected with jquery.

Ex:

<div class="input-group input-group-lg">
                          <span class="input-group-addon">R$</span>
                          <input id="valor" type="number" min="0" class="form-control payment-value" aria-label="Amount (to the nearest dollar)" placeholder="Valor do pagamento">
                        </div> 



<div class="input-group input-group-lg">
                          <select class="form-control plan">
                              <option value="39256">Plano R$ 10,00</option>
                              <option value="45659">Plano R$ 11,00</option>
                          </select>
                        </div>

In my JS I have:

this.PLAN_ID = $('.plan').val();

and a var data:

'plan': parent.PLAN_ID,

The problem is that when I change the 'plane', the value is not dynamically changed, ie the plane gets 39256 which is the default item, could anyone give a help?

Thank you

    
asked by anonymous 20.06.2016 / 22:10

1 answer

1

If I understood correctly, this is what you want:

$('.plan').on('change', function() {
  var plan = $(this).val();
  $('#valor').val(plan);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><divclass="input-group input-group-lg">
                          <span class="input-group-addon">R$</span>
                          <input id="valor" type="number" min="0" class="form-control payment-value" value="39256" aria-label="Amount (to the nearest dollar)" placeholder="Valor do pagamento">
                        </div> 



<div class="input-group input-group-lg">
                          <select class="form-control plan">
                              <option value="39256">Plano R$ 10,00</option>
                              <option value="45659">Plano R$ 11,00</option>
                          </select>
                        </div>

I did not do it because I do not know if this is what I want, but if there are only these two hypotheses, and to not be able to directly value the input #valor , you can add the disabled attribute to this input#valor

    
20.06.2016 / 22:15