mardi 19 mars 2019

JQuery and checkbox trigger

I want to use an existing checkbox in my form that invoke this function when it's checked (or clicked).

$(function() {
  var $residenza = $('#residenza');
  var $domicilio = $('#domicilio');
  var $capResidenza = $('#capResidenza');
  var $capDomicilio = $('#capDomicilio');

  function onChange() {
    $domicilio.val($residenza.val());
    $capDomicilio.val($capResidenza.val());
  };
  $('#residenza')
    .change(onChange)
    .keyup(onChange);
  $('#capResidenza')
    .change(onChange)
    .keyup(onChange);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>



Aucun commentaire:

Enregistrer un commentaire