Calculate age when date of birth is filled out

Calculate age when date of birth is filled out

paintitblackpaintitblack Posts: 60Questions: 20Answers: 0

Hi,

is it possible to calculate the age immediately after the field "date of birth" is filled out and show the result right to the field?

With options “message” or “fieldInfo” it possible to add texts left or below the field.

How is possible to put them right to the field and how could it calculate the age?

Thanks for any support.

Patrick

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,864Questions: 1Answers: 10,136 Site admin

    This is with Editor? If so, the dependent() method can be used to listen for changes on one field and cause an update to another.

    Regards,
    Allan

  • paintitblackpaintitblack Posts: 60Questions: 20Answers: 0

    Thats a relly nice function.

    I used for an easier issue to calculate the profit

        siteEditor.dependent( 'quantity', function ( val, data, callback ) {
                 if(siteEditor.field('quantity').val()>0 && siteEditor.field('purchasePrice').val()>0) {
                         var result = siteEditor.field('quantity').val()*siteEditor.field('purchasePrice').val();
                         siteEditor.field('purchasePrice').fieldInfo( $.number(result, 2, '.', ',') );
                 }
        } );
        siteEditor.dependent( 'purchasePrice', function ( val, data, callback ) {
                 if(siteEditor.field('quantity').val()>0 && siteEditor.field('purchasePrice').val()>0) {
                         var result = siteEditor.field('quantity').val()*siteEditor.field('purchasePrice').val();
                         siteEditor.field('purchasePrice').fieldInfo( $.number(result, 2, '.', ',') );
                 }
        } );
    

    Is it possible to combine both in one function? I created one separet function but it wasn't possible to call the siteEditor variable.

    Thanks in advance

    Patrick

  • allanallan Posts: 61,864Questions: 1Answers: 10,136 Site admin
    Answer ✓

    Is it possible to combine both in one function?

    They look identical. Are they? If so you can pass the first parameter of dependent() as an array - e.g. [ 'quantity', 'purchasePrice' ].

    Allan

  • paintitblackpaintitblack Posts: 60Questions: 20Answers: 0
    edited January 2017

    Yes they are dependent.

    This works pretty well:

    siteEditor.dependent( [ 'quantity', 'purchasePrice' ], function ( val, data, callback ) {
             if(siteEditor.field('quantity').val()>0 && siteEditor.field('purchasePrice').val()>0) {
                     var result = siteEditor.field('quantity').val()*siteEditor.field('purchasePrice').val();
                     siteEditor.field('purchasePrice').fieldInfo( $.number(result, 2, '.', ',') );
             }
    } );
    

    Thank you very much

    Patrick

    Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

This discussion has been closed.