Welcome to the nuBuilder forums!

Please register and login to view forums and other content only available to registered users.

Field Values

Post Reply
stevem
Posts: 8
Joined: Tue Jun 24, 2014 12:59 pm

Field Values

Unread post by stevem »

Hello,

Is it possible to update a field value on a form based with the value of another field or ifram on the form.
I am wanting to change the field age based on the result of the date of birth field. The result is currently being displayed within an iframe on the same form.

I have the following in the events section of a button
$( "#age" ).val(("#clientiframe").val);

If I use $( "#age" ).val('clientiframe'); then the age field contains the value clientframe

Thanks
Steve
massiws
Posts: 503
Joined: Thu May 24, 2012 2:08 am
Location: Milan, Italy
Contact:

Re: Field Values

Unread post by massiws »

Steve,
stevem wrote:$( "#age" ).val(("#clientiframe").val);

If I use $( "#age" ).val('clientiframe'); then the age field contains the value clientframe
there is a syntax error in your code (see here). Try this:

Code: Select all

$( "#age" ).val( $( "#clientiframe" ).val() ); 
Have you seen this post?

Max.
stevem
Posts: 8
Joined: Tue Jun 24, 2014 12:59 pm

Re: Field Values

Unread post by stevem »

Hi Max,

I looked at the link to the external post and this works apart from the date I'm using is in the format dd-MMM-yyyy

I'm still trying to understand Java and so do not have a clue how to convert the code example so that it excepts the format above.

Any help with this would be appreciated.
Thanks
steve
massiws
Posts: 503
Joined: Thu May 24, 2012 2:08 am
Location: Milan, Italy
Contact:

Re: Field Values

Unread post by massiws »

Steve,
in the Events tab of your age field insert a new event:
- Event Name: onfocus
- Javascript: this code

Code: Select all

$( "#age" ).val(function() {
    var d = new Date($( "#your-date-of-birth-field-name" ).val());
    var dob = d.getFullYear();
    var d = new Date();
    var today = d.getFullYear();
    return (isNaN(today - dob) ? 0 : (today - dob));
});
Hope this helps,
Max
Post Reply