Forums

Billing Address Same As General Address

melvins138 13 Feb, 2009
I have a form where people are going to make donations to a school. They must put in their Donor Info which includes address, then there are fields for their billing address that matches the CC. What is the code or how do I set it up to where the donor can click a button and have the Donor Address Info automatically fill in the Billing Address Info?

Oh, I am using the Authorize.net plug-in.

Sorry for the newbie question. But I'm a little lost.

Thanks
Melvins
melvins138 13 Feb, 2009
nevermind, I think I figured it out. I can use a js that says something like this:
the form looks like this:

<form>
Name: 
Donor Name: <input name="a_Name" type="text" id="a_Name" size="30" maxlength="150" class="cf_inputbox required">
<br>
Donor Address: <input name="a_Address" type="text" id="a_Address" size="30" maxlength="150" class="cf_inputbox required">
<br>
<input type="checkbox"  name="billingtoo" onclick="FillBilling(this.form)">
Copy to billing fields.
<br>
Billing Name: <input name="b_Name" type="text" id="b_Name" size="30" maxlength="150" class="cf_inputbox required">
<br>
Billing Address: <input name="b_Address" type="text" id="b_Address" size="30" maxlength="150" class="cf_inputbox required">
<br>
<input type="submit">
</form>


With the js like this:

<script type="text/javascript" language="JavaScript"><!--
function FillBilling(f) {
if(f.billingtoo.checked == true) {
    f.a_Name.value = f.b_Name.value;
    f.a_Address.value = f.b_Address.value;
    }
}
//--></script>
GreyHead 13 Feb, 2009
Hi melvins138,

Looks good to me.

Bob
sitebuildernow 14 Aug, 2009
Ok, I say "uncle" I've tried and tried this code for giving the option to use previously entered data to fill in other fields on the form (it's a long form that can be seen here: http://asnwonline.com/2009/index.php?option=com_chronocontact&Itemid=38)

What I want to do is give them the option to auto populate the jobsite info with the requester info by clicking the box "same as requester" (eventually I will offer the same option for billing details if I can get this to work"

I have added this code to my form html:

<!--begin autofill code for jobsite //-->
<div class="form_item">
<div class="form_element cf_checkbox">
<input type="checkbox" name="jobsite" onclick="FillJob(this.form)">
Same as Requester.
<div class="cfclear"> </div>
</div>
<!-- end auto code for jobsite //-->

and this code in the form javascript box:
function FillJob(f) {
if(f.jobsite.checked == true) {
f.rfname.value = f.onsite.value;
f.rphone.value = f.onsitephone.value;
f.raddress1.value = f.onsite1.value;
f.raddress2.value = f.onsiteroom.value;
f.rcity.value = f.onsitecity.value;
f.rstate.value = f.onsitestate.value;
f.rzip.value = f.onsitezip.value;
}
}

I have "save to database before email" checked. (wasn't sure if this was needed)
But when you check the "same as requester" checkbox on the form the Requester info disappears and nothing is entered into the jobsite details. Help??
sitebuildernow 14 Aug, 2009
Figured it out myself - 2 things: 1 - I had to remove the js opening and closing code (cf does that for me) 2. I had my data reversed (I was telling it to copy the blank fields from job site into the requester fields insted of the other way around - works now! Here is how I had to redo the code:
function FillJob(f) {
if(f.jobsite.checked == true) {
f.onsite.value = f.rfname.value;
f.onsitephone.value = f.rphone.value;
f.onsite1.value = f.raddress1.value;
f.onsiteroom.value = f.raddress2.value;
f.onsitecity.value = f.rcity.value;
f.onsitestate.value = f.rstate.value;
f.onsitezip.value = f.rzip.value;
}
}
sitebuildernow 15 Aug, 2009
I figured it out all by my lonesome - after many trial and error code fidgeting.

Stuck again... Ok, so I got the copy script to work for one section of the form - how do I get it to work for another section? So I have 3 sections that could contain the same information - Requester information, Job Site Information and Billing information. From this post I have figured out how to write the html for copying from the requester fields to the job site fields if a box is checked - works great! So now I want to add a checkbox for the billing fields. So the user has the option of checking the "same as requester" for the job site details and/OR the billing details (for example it could be the job site is different than the requester details but the billing information is the same). I tried to do this by adding another if statement and calling it BillTo and pasting it in the same box as the other form javascript but it doesn't work. How do I give a form 2 different Javascripts?
GreyHead 15 Aug, 2009
Hi sitebuildernow,

You cna add as many JavaScripts as you like to your form. The key is that what you have there is a javascript function function FillJob(f) { . . . } and a code snippet to trigger the function onclick="FillJob(this.form)

By using different function names (or if statements inside the functions) you can call different functions in different places.

Bob
sitebuildernow 15 Aug, 2009
Thanks Bob, I did figure it out - what I was struggling with was the syntax - finally figured out where to put all of my curly brackets etc. I've never written javascript before (just copied and pasted other peoples' snippets) so it is still a learning process.
mashdun 16 Mar, 2010
I am trying to use this onclick fill function and it works fine in Firefox but cannot get it to work in IE. Anyone else have this issue?
This topic is locked and no more replies can be posted.