javascript - DOM event chaining not working -


so, hints why not working? i'm trying both input fields ('pagamento' , 'parcelas') @ preset if 'boleto' radiobox selected, ('1' , 'mercadopago', respectively, , again user input if 'cartão' radiobox selected.

function boleto() {      if(document.getelementbyid('tipodepagamento').checked==true){          document.getelementbyid('pagamento').value = 'mercadopago';          document.getelementbyid('pagamento').disabled = true;          document.getelementbyid('parcelas').value = '1';          document.getelementbyid('parcelas').disabled = true;      }      else{          document.getelementbyid('pagamento').disabled = false;          document.getelementbyid('parcelas').disabled = false;      }   }
<div class="col-md-6">      <label class="radio-inline">          <input type="radio" name="tipodeconta" id="tipodepagamento2" value="cartão" checked onclick="boleto();">cartão de crédito      </label>  </div>  <div class="col-md-6">      <label class="radio-inline">          <input type="radio" name="tipodeconta" id="tipodepagamento" value="boleto" onclick="boleto();">boleto      </label>  </div>  <label>plataforma de pagamento</label>  <select class="form-control" onclick="fpagamento();validador();" onkeyup="fpagamento();" name="pagamento" id="pagamento">      <option value="selecione">selecione</option>      <option value="paypal">paypal</option>      <option value="mercadopago">mercado pago</option>  </select>  <label>número de parcelas</label>  <select class="form-control" id="parcelas" name="parcelas">      <option value="1">1x</option>      <option value="2">2x</option>  </select>

fiddle = http://kodeweave.sourceforge.net/editor/#d692f9461c022ee386cb2c5329f453c4

i see few problems code.

<input type="radio" name="tipodeconta" id="tipodepagamento" value="boleto" onclick="boleto();"> <select class="form-control" onclick="fpagamento();validador();" onkeyup="fpagamento();" 

first off shouldn't use onclick radio button, or select element. use onchange instead means won't need call onkeyup="fpagamento();"

btw: code wet. in addition it's bad practice add onclick attribute in html (same goes other events). put javascript in .js file , edit there.

var tipodeconta = $('input[name=tipodeconta]'),      cartao      = document.queryselector('#tipodepagamento2'),      pagamento   = $('#pagamento'),      checkthis   = $('.form-control');    tipodeconta.on('change', function() {    if (cartao.checked) {      pagamento.val('mercadopago');    }    (cartao.checked) ? checkthis.prop('disabled', true) : checkthis.removeattr('disabled');  }).trigger('change');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>    <div class="panel panel-default">    <div class="panel-body">      <div class="col-md-6">        <label class="radio-inline">          <input type="radio" name="tipodeconta" id="tipodepagamento2" value="cartão" checked="">           cartão de crédito        </label>      </div>      <div class="col-md-6">        <label class="radio-inline">          <input type="radio" name="tipodeconta" id="tipodepagamento" value="boleto">          boleto        </label>      </div>    </div>  </div>    <label>plataforma de pagamento</label>  <select class="form-control" name="pagamento" id="pagamento" disabled="">    <option value="selecione">selecione</option>    <option value="paypal">paypal</option>    <option value="mercadopago">mercado pago</option>  </select>  <label>número de parcelas</label>  <select class="form-control" id="parcelas" name="parcelas" disabled="">    <option value="1">1x</option>    <option value="2">2x</option>  </select>


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -