vfontjr

Hide/show fields based on anchorlink

May 26th, 2020
52
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script>
  2. jQuery(document).ready(function($) {
  3.     "use strict";
  4.  
  5.     $( function() {
  6.         /* first make sure both field containers are not shown
  7.          * you can also initially hide these fields by adding a class
  8.          * to hide them in the fields' source code on the form's
  9.          * Customize HTML page.
  10.          * If using a class, comment out this code
  11.          */
  12.          
  13.         /* first field container to hide
  14.          * Change 152 to the id of your first field
  15.          */
  16.         $("#frm_field_152_container").hide();
  17.        
  18.         /* second field container to hide
  19.          * Change 153 to the id of your first field
  20.          */
  21.         $("#frm_field_153_container").hide();
  22.            
  23.         /* get the url */
  24.         var this_url = window.location.href;
  25.        
  26.         /* only process pages that pass the correct query string
  27.          * change "#a" and "#b" to the names of the anchorlink you're passing
  28.          * to this function in the url */
  29.         if ( this_url.indexOf("#a") !== -1  || this_url.indexOf("#b") !== -1 ) {
  30.        
  31.             if ( this_url.indexOf("#a") !== -1 ) {
  32.                 $("#frm_field_152_container").show();
  33.             } else {
  34.                 $("#frm_field_153_container").show();
  35.             }
  36.         }
  37.     });
  38. });
  39. </script>
RAW Paste Data