Field Values

Field Values

Unread postby stevem » Thu Jul 03, 2014 12:20 am

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
stevem
 
Posts: 8
Joined: Tue Jun 24, 2014 8:29 pm

Re: Field Values

Unread postby massiws » Thu Jul 03, 2014 7:48 am

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.
massiws
 
Posts: 503
Joined: Thu May 24, 2012 9:38 am
Location: Milan, Italy

Re: Field Values

Unread postby stevem » Thu Jul 03, 2014 8:15 pm

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
stevem
 
Posts: 8
Joined: Tue Jun 24, 2014 8:29 pm

Re: Field Values

Unread postby massiws » Fri Jul 04, 2014 9:31 am

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
massiws
 
Posts: 503
Joined: Thu May 24, 2012 9:38 am
Location: Milan, Italy


Return to Custom Code

Who is online

Users browsing this forum: No registered users and 4 guests