Guest User

Untitled

a guest
Jan 16th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. $("#wood_typeschecklist input").change(function() {
  2. var destEl = this.id.split("-");
  3. //a. Changed selector to look for starts with selector as the
  4. //checkbox value returned is wood_type-<number>
  5. //which doesn't match any existing id
  6.  
  7. //b. `.split` splits the string when it matches its
  8. //separator and so it was returning 3 tokens not 2 (in,wood_types,126)
  9. var $matchingElem = $("li[id^=" + destEl[1] + '-' + destEl[2] + "]", $("#acf-wood_species_availability"));
  10. ($(this).attr("checked") !== undefined) ? $matchingElem.show() : $matchingElem.hide();
  11. });
  12.  
  13. // start off by hiding the second options
  14. $("#acf-wood_species_availability li").hide();
  15.  
  16. //add a click method to the inputs
  17. $("#wood_typeschecklist input").click(function() {
  18. //verify that it's checked, if so, show the other input of the same value (and check it also)
  19. if ($(this).is(':checked')) {
  20. $('#acf-wood_species_availability input[value="' + $(this).val() + '"]').attr('checked', true).parents('.popular-category').show();
  21. }
  22. //if it's unchecked, hide the other input and uncheck this one
  23. else {
  24. $('#acf-wood_species_availability input[value="' + $(this).val() + '"]').attr('checked', false).parents('.popular-category').hide();
  25. }
  26. });
  27.  
  28. //now let's add click methods to the other checkboxes in case user clicks on them, if so, we hie this checkbox and uncheck the other one.
  29. $("#acf-wood_species_availability input").click(function() {
  30. $(this).attr('checked', '').parents('.popular-category').hide();
  31. $('#wood_typeschecklist input[value="' + $(this).val() + '"]').attr('checked', false);
  32. });
Add Comment
Please, Sign In to add comment