Field 1 Equal to Field 2

Got a question? Get FormBoss help here.

Field 1 Equal to Field 2

Postby princemac » Tue Jul 27, 2010 10:01 pm

Hi there,

What I'm trying to do is this:

I have 2 fields, contact's first name and contact's last name then I have 2 other fields, passenger's first name and passenger's last name, then I have a check box "same as contact".

What I want is that when I click the check box the value for the contact's first and last name is filled into the passenger's first and last name field.

How can I do this?

Thanks in advance.
princemac
 
Posts: 9
Joined: Sun Jul 25, 2010 1:49 am

Re: Field 1 Equal to Field 2

Postby admin » Sat Aug 14, 2010 11:54 am

Greetings,

A solid question.

To do so we'll need to create a small script to grab the values and push them to our other fields. This requires custom JavaScript, so I have just created a sample job for you that does it.

Please let me know what you think,

Matt
Attachments
checkbox-populate-text.zip
(2.73 KiB) Downloaded 4 times
admin
Site Admin
 
Posts: 421
Joined: Sat Sep 27, 2008 11:02 am

Re: Field 1 Equal to Field 2

Postby princemac » Tue Aug 17, 2010 1:51 pm

Thanks Matt,

Your method worked but I also did it an alternate way.

In the Checkbox's "Extra Attribute(s) JS Etc" I used this code:
Code: Select all
onclick="
if (document.getElementById('checkbox210').checked == 1) {
   document.getElementById('text13').value = document.getElementById('text6').value;
   document.getElementById('text14').value = document.getElementById('text5').value;
   document.getElementById('text15').value = document.getElementById('text4').value;
   document.getElementById('text16').value = document.getElementById('text7').value;
}
else {
   return(0);
}"


And it worked, thanks again for your help.
princemac
 
Posts: 9
Joined: Sun Jul 25, 2010 1:49 am

Re: Field 1 Equal to Field 2

Postby admin » Mon Aug 23, 2010 9:10 pm

Well played : )

Just to toss this out, we can always include the jQuery or Prototype JS libraries:

page-js-libraries.png
page-js-libraries.png (14.81 KiB) Viewed 33 times


Which would, for example, with Prototype, allow us to do this:

Code: Select all
$('text16').value = $('text7').value;


Instead of this:

Code: Select all
document.getElementById('text16').value = document.getElementById('text7').value;


Not a huge change, but simple, and of course, less prone to errors.
admin
Site Admin
 
Posts: 421
Joined: Sat Sep 27, 2008 11:02 am


Return to FormBoss Support

Who is online

Users browsing this forum: No registered users and 1 guest

cron