CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviMember (Moderator: Deepak Srivastava) »
  • HOW TO: Use jQuery to show/hide the Organization "On Behalf of" section
Pages: [1]

Author Topic: HOW TO: Use jQuery to show/hide the Organization "On Behalf of" section  (Read 1619 times)

CiviTeacher.com

  • I live on this forum
  • *****
  • Posts: 1282
  • Karma: 118
    • CiviTeacher
  • CiviCRM version: 3.4 - 4.5
  • CMS version: Drupal 6&7, Wordpress
  • MySQL version: 5.1 - 5.5
  • PHP version: 5.2 - 5.4
HOW TO: Use jQuery to show/hide the Organization "On Behalf of" section
December 16, 2011, 08:59:25 pm
Some memberships may be for Organizations only, some for individuals only.  It is confusing to present the 'on behalf of Organization' section when it is not appropriate to do so.

It is easy to use jQuery to show and hide these sections when a person clicks the different membership options.

1. Create a Drupal block or edit a custom Main.tpl file that will have some jQuery in it - whichever one works for you
2. Make sure the code you are about to make only shows up on the contribution page of your choosing.  This can be done through jQuery or through using a Contribution/#/Main.tpl template system in CiviCRM.  Look up this documentation and this too.
3. Add this jQuery code, careful to substitute in the id# of the radio buttons for your installation.  These will be different than my example here.
Code: [Select]
<script>
cj('#CIVICRM_QFID_X_X').click(function() {
cj('#is_for_organization').attr('checked', true);
showOnBehalf(true);
cj('#is_for_organization').hide();
cj('div.is_for_organization-section').show();

  });
cj('#CIVICRM_QFID_X_X').click(function() {
cj('#is_for_organization').attr('checked', true);
showOnBehalf(true);
cj('#is_for_organization').hide();
cj('div.is_for_organization-section').show();
  });
cj('#CIVICRM_QFID_8_8').click(function() {
cj('#is_for_organization').attr('checked', false);
showOnBehalf(false);
cj('div.is_for_organization-section').hide();
  });
cj('#CIVICRM_QFID_5_2').click(function() {
cj('#is_for_organization').attr('checked', false);
showOnBehalf(false);
cj('div.is_for_organization-section').hide();
  });
cj('div.is_for_organization-section').hide();
</script>
4. If you put that in a Main.tpl, don't forget to surround your <script> with {literal} tags for Smarty template engine

There you go.  It will show and hide the 'on behalf of' for certain membership types.
Try CiviTeacher: the online video tutorial CiviCRM learning library.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviMember (Moderator: Deepak Srivastava) »
  • HOW TO: Use jQuery to show/hide the Organization "On Behalf of" section

This forum was archived on 2017-11-26.