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) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • jquery and civievent registration issues
Pages: [1]

Author Topic: jquery and civievent registration issues  (Read 661 times)

dinkpwns

  • I’m new here
  • *
  • Posts: 17
  • Karma: 0
  • CiviCRM version: 3.4.4
  • CMS version: Drupal 6.22
jquery and civievent registration issues
July 15, 2011, 07:27:30 pm
I want certain questions to show/hide when a specific answer is given earlier in the form. (eg "are you a student?" yes/no. yes->another question appears "undergrad or grad?" no->the undergrad/grad student question remains hidden.)

What I've done:
-Read this blog post about jquery and thought this would be a fantastically easy way to do this
-I'm a bit of a jquery noob so I read more about it here
-Implemented the first example Hershel gave (multiple register buttons) and everything worked as expected
-Made civicrm_custom/CRM/Event/Form/Registration/Register.extra.tpl

I was able to append one div to another however when I tried to use the .click function on a checkbox in my form nothing happened. I was able to implement the .click on custom components that I put outside my script in Register.extra.tpl file. Am I just referencing the checkbox improperly? This is how I was calling it as a test.
Code: [Select]
$('#custom_9[yes].form-checkbox').click(function() { 
alert('you win!');
});

Any help/ advice is much appreciated!

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: jquery and civievent registration issues
July 17, 2011, 10:45:12 am
This code definitely looks wrong. I would have to see your page to know the correct code however. You can contact me offline if it's private.
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

dinkpwns

  • I’m new here
  • *
  • Posts: 17
  • Karma: 0
  • CiviCRM version: 3.4.4
  • CMS version: Drupal 6.22
Re: jquery and civievent registration issues
July 18, 2011, 04:57:04 pm

I have successfully been able to get events triggered when a checkbox is clicked!(Thanks for all the help, Hershel :D ) The code that goes into Register.extra.tpl becomes:

Code: [Select]
{literal}
<script>
$(document).ready(function () {
//when this checkbox is clicked it will print "clicked!" in the console
$('#custom_9\\[yes\\]').click(function() { console.log('clicked!') });
});
</script>
{/literal}
All you need is the ID of the component (no need for the class as well as I had in my OP) and in this case I needed to put in the escape character ("\\") before the brackets so everything would get interpreted correctly. And now its just a matter of some if-statements to show/hide certain fields properly. Something else I learned on this mini-adventure, use the console, not alerts.

Even though I have just started jQuery this gives me motivation to put jquery EVERYWHERE!



Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • jquery and civievent registration issues

This forum was archived on 2017-11-26.