1

I am trying to hide check-box selectors in the custom search module when the page initially loads and then have a clickable link to show them. I have the clickable link working but the check-boxes are initially in a visible state. How can I hide the check boxes when the page/module loads? I tried placing the following code in my THEME_form_alter(&$form, &$form_state, $form_id) function

drupal_add_js('jQuery(document).ready(function () { $("#edit-custom-search-types")[0].hide(); });', 'inline');

and

drupal_add_js('jQuery(document).ready(function () { $("#edit-custom-search-types").hide(); });', 'inline');

But neither worked. Any help would be appreciated. thanks

-2

For Drupal 7

drupal_add_js('(function ($) { $("#edit-custom-search-types").hide(); }(jQuery));', 'inline');

Working with JavaScript and jQuery

  • worked perfectly, thanks! here is my final code: drupal_add_js('(function ($) { $("#edit-custom-search-types").css("visibility","hidden"); }(jQuery));', 'inline'); drupal_add_js('(function ($) { $("#adv_search_link").click(function() { if( $("#edit-custom-search-types").css("visibility") == "hidden" ) { $("#edit-custom-search-types").css("visibility","visible"); } else { $("#edit-custom-search-types").css("visibility","hidden"); }});}(jQuery));', 'inline'); – John R May 1 '14 at 15:02
  • 1
    Why did this get down votes? – John R May 11 '14 at 19:06
0

the easiest way of adding custom javascript-snippets is to create a custom.js file in your themefolder and declare it in your theme.info file like scripts[] = custom.js. Add all your snippets there.

In your JS file you can hide the elements. If you have multiple checkboxes create an array and hide them with a for each loop.

example

// create array with stuff you want to hide
    checkboxes = [
        '#checkbox1',
        '#checkbox2',
    ];

// Hide arrays
    for (i = 0; i < checkboxes.length; i++) {
        jQuery(checkboxes[i]).hide();
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.