Title: Add script into a record?
Last modified: February 22, 2017

---

# Add script into a record?

 *  [cetaceancousins](https://wordpress.org/support/users/cetaceancousins/)
 * (@cetaceancousins)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/add-script-into-a-record/)
 * Hi,
 * I wish to add a script into a record to display age using a javascript code –
   is this possible? I have made the field a rich text Form Element; the code works
   in a normal wordpress post but doesn’t in a field which is annoying.
 * Any help would be appreciated.

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Author [Roland Barker](https://wordpress.org/support/users/xnau/)
 * (@xnau)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/add-script-into-a-record/#post-8836575)
 * You need to use a custom template, you can add your javascript to the form in
   that template:
 * [Using Participants Database Custom Templates](https://xnau.com/work/wordpress-plugins/participants-database/participants-database-documentation/pdb-templates/)
 *  Thread Starter [cetaceancousins](https://wordpress.org/support/users/cetaceancousins/)
 * (@cetaceancousins)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/add-script-into-a-record/#post-8839691)
 * Hello
 * I have tried to follow your documentation and not getting anywhere; I am not 
   very good with php and javascript (more of a html girl)
 * This is the javascript that needs adding
 *  <script language=”JavaScript”>function calculateAge(birthMonth, birthDay, birthYear)
   {
   todayDate = new Date(); todayYear = todayDate.getFullYear(); todayMonth = todayDate.
   getMonth(); todayDay = todayDate.getDate(); age = todayYear – birthYear;
 *  if (todayMonth < birthMonth – 1)
    { age–; }
 *  if (birthMonth – 1 == todayMonth && todayDay < birthDay)
    { age–; } return age;}
   </script>
 * and this is the supporting code that needs to go into the field named _age_
    
   <script language=”JavaScript”>Date.prototype.ageLastBirthday = function(dob) {
   var cy = this.getFullYear(); var by = dob.getFullYear(); var db = new Date(1996,09,07);
   db.setFullYear(cy); var adj = (this-db<0) ? 1 : 0; return cy – by – adj; }</script
   >
 *  <script type=”text/javascript”>
    document.write(” ” + calculateAge(10,12,2010)
   + “” ); </script>
 * I am sure its something obivious I am doing wrong but any help would be most 
   invaluable.
 * CC
    -  This reply was modified 9 years, 3 months ago by [cetaceancousins](https://wordpress.org/support/users/cetaceancousins/).

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Add script into a record?’ is closed to new replies.

 * ![](https://ps.w.org/participants-database/assets/icon-256x256.jpg?rev=1389807)
 * [Participants Database](https://wordpress.org/plugins/participants-database/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/participants-database/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/participants-database/)
 * [Active Topics](https://wordpress.org/support/plugin/participants-database/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/participants-database/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/participants-database/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [cetaceancousins](https://wordpress.org/support/users/cetaceancousins/)
 * Last activity: [9 years, 3 months ago](https://wordpress.org/support/topic/add-script-into-a-record/#post-8839691)
 * Status: not resolved