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) »
  • Adding JavaScript to profile form element using custom hook or template?
Pages: [1]

Author Topic: Adding JavaScript to profile form element using custom hook or template?  (Read 1608 times)

dbsavage

  • Guest
Adding JavaScript to profile form element using custom hook or template?
October 16, 2009, 09:32:08 am
Hi,

I'm trying to set up a profile form with a dropdown select field where, if a user selects "Other", a text field will be spawned where the user can enter additional information. The way I thought about doing this was to include the "Other" text field in the profile, and add a JavaScript "onchange" event to the dropdown form element to keep the text field hidden unless a certain option is selected. I'm having trouble figuring out how to insert the JavaScript; I'm assuming I would use either a buildForm hook or a custom profile form template, but I'm not sure how I would go about it either way. Any advice is appreciated.

Thanks -

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Adding JavaScript to profile form element using custom hook or template?
October 16, 2009, 10:52:39 am

I would do the following:

1. create a custom select field that includes the option other

2. create a custom text field called other_text

3. add these 2 fields to the profile

4. customize the profile template form for that specific profile (http://wiki.civicrm.org/confluence/display/CRMDOC/Customize+Built-in,+Profile,+Contribution+and+Event+Registration+Screens)

5. add javascript to hide other_text by default and show it if the option other is chosen

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

dbsavage

  • Guest
Re: Adding JavaScript to profile form element using custom hook or template?
October 16, 2009, 03:16:26 pm
Thanks for the response; this helped. I ended up adding the javascript to the event registration template instead, since that's where I'm having the profile show up, but the basic idea is the same....

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Adding JavaScript to profile form element using custom hook or template?

This forum was archived on 2017-11-26.