Advertisement
Antalis-HQ

Code for multi tickboxes & dynamic adresses

Mar 25th, 2021
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. <script>
  2.  
  3. // by default, hide the address fields
  4.  
  5. $(document).ready(function() {
  6. $('input[name=address1]').closest('div[id*=formElement]').hide();
  7. $('input[name=address2]').closest('div[id*=formElement]').hide();
  8. $('input[name=city]').closest('div[id*=formElement]').hide();
  9. $('input[name=zipPostal]').closest('div[id*=formElement]').hide();
  10. $('select[name=country]').closest('div[id*=formElement]').hide();
  11. });
  12.  
  13. // show the address fields when one of the checkboxes is checked
  14.  
  15. $(document).on('change', 'input[name*=tickbox]', function(){
  16.  
  17. var tickboxChecked=$('input[name*=tickbox]:checked').length;
  18. // console.log(tickboxChecked);
  19.  
  20. if(tickboxChecked>0){
  21. $('input[name=address1]').closest('div[id*=formElement]').show();
  22. $('input[name=address2]').closest('div[id*=formElement]').show();
  23. $('input[name=city]').closest('div[id*=formElement]').show();
  24. $('input[name=zipPostal]').closest('div[id*=formElement]').show();
  25. $('select[name=country]').closest('div[id*=formElement]').show();
  26.  
  27. }
  28. // else hide the address fields if none of the checkboxes are checked
  29. else if (tickboxChecked==0) {
  30.  
  31. $('input[name=address1]').closest('div[id*=formElement]').hide();
  32. $('input[name=address2]').closest('div[id*=formElement]').hide();
  33. $('input[name=city]').closest('div[id*=formElement]').hide();
  34. $('input[name=zipPostal]').closest('div[id*=formElement]').hide();
  35. $('select[name=country]').closest('div[id*=formElement]').hide();
  36.  
  37. }
  38. });
  39. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement