• 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 xnau webdesign

    (@xnau)

    You need to use a custom template, you can add your javascript to the form in that template:

    Using Participants Database Custom Templates

    Thread Starter cetaceancousins

    (@cetaceancousins)

    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

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Add script into a record?’ is closed to new replies.