Page 1 of 1

Field Values

Unread postPosted: Thu Jul 03, 2014 12:20 am
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

Re: Field Values

Unread postPosted: Thu Jul 03, 2014 7:48 am
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.

Re: Field Values

Unread postPosted: Thu Jul 03, 2014 8:15 pm
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

Re: Field Values

Unread postPosted: Fri Jul 04, 2014 9:31 am
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