/    Sign up×
Community /Pin to ProfileBookmark

Copy Fields Script

Hi Guys

I would like to use the “Copy Fields” script as I was direct to this script to solve a problem I was having.

But the script requires a checkbox to be ticked, the script is:

<!– TWO STEPS TO INSTALL COPY FIELDS:

  • 1. Copy the coding into the HEAD of your HTML document

  • 2. Add the last code into the BODY of your HTML document –>
  • <!– STEP ONE: Paste this code into the HEAD of your HTML document –>

    <HEAD>

    <SCRIPT LANGUAGE=”JavaScript”>

    <!– This script and many more are available free online at –>
    <!– The JavaScript Source!! [url]http://javascript.internet.com[/url] –>

    <!– Begin
    var ShipFirst = “”;
    var ShipLast = “”;
    var ShipEmail = “”;
    var ShipCompany = “”;
    var ShipAddress1 = “”;
    var ShipAddress2 = “”;
    var ShipCity = “”;
    var ShipState = “”;
    var ShipStateIndex = 0;
    var ShipZip = “”;
    var ShipConfirm = 0;

    function InitSaveVariables(form) {
    ShipFirst = form.ShipFirst.value;
    ShipLast = form.ShipLast.value;
    ShipEmail = form.ShipEmail.value;
    ShipCompany = form.ShipCompany.value;
    ShipAddress1 = form.ShipAddress1.value;
    ShipAddress2 = form.ShipAddress2.value;
    ShipCity = form.ShipCity.value;
    ShipZip = form.ShipZip.value;
    ShipStateIndex = form.ShipState.selectedIndex;
    ShipState = form.ShipState[ShipStateIndex].value;
    ShipConfirm = form.ShipConfirm.checked;
    }

    function ShipToBillPerson(form) {
    if (form.copy.checked) {
    InitSaveVariables(form);
    form.ShipFirst.value = form.BillFirst.value;
    form.ShipLast.value = form.BillLast.value;
    form.ShipEmail.value = form.BillEmail.value;
    form.ShipCompany.value = form.BillCompany.value;
    form.ShipAddress1.value = form.BillAddress1.value;
    form.ShipAddress2.value = form.BillAddress2.value;
    form.ShipCity.value = form.BillCity.value;
    form.ShipZip.value = form.BillZip.value;
    form.ShipState.selectedIndex = form.BillState.selectedIndex;
    form.ShipConfirm.checked = form.BillConfirm.checked;
    }
    else {
    form.ShipFirst.value = ShipFirst;
    form.ShipLast.value = ShipLast;
    form.ShipEmail.value = ShipEmail;
    form.ShipCompany.value = ShipCompany;
    form.ShipAddress1.value = ShipAddress1;
    form.ShipAddress2.value = ShipAddress2;
    form.ShipCity.value = ShipCity;
    form.ShipZip.value = ShipZip;

    form.ShipState.selectedIndex = ShipStateIndex;
    form.ShipConfirm.checked = ShipConfirm;
    }
    }
    // End –>
    </script>
    </HEAD>

    <!– STEP TWO: Copy this code into the BODY of your HTML document –>

    <BODY>

    <center>
    <form method=”post” action=”http://www.your-web-site-address-here.com/script.cgi” name=”billform”>
    <table border=”1″ cellspacing=”0″ cellpadding=”3″ width=”400″>

    <tr bgcolor=”#003399″>
    <td colspan=2 width=”100%” bgcolor=”#003399″>
    <b><font color=white size=”-1″ face=”arial, helvetica”>Billing Information</font></b>
    </td>
    </tr>
    <tr>
    <td>
    <font size=”-1″ face=”arial, helvetica”>First Name:</font>
    </td>
    <td>
    <input type=”text” size=”15″ maxlength=”50″ name=”BillFirst”>
    </td>
    </tr>
    <tr>
    <td>
    <font size=”-1″ face=”arial, helvetica”>Last Name:</font>
    </td>
    <td>
    <input type=”text” size=”15″ maxlength=”50″ name=”BillLast”>
    </td>
    </tr>
    <tr>
    <td>
    <font size=”-1″ face=”arial, helvetica”>E-Mail:</font>
    </td>
    <td>
    <input type=”text” size=”15″ name=”BillEmail”>
    </td>
    </tr>
    <tr>
    <td>
    <font size=”-1″ face=”arial, helvetica”>Company:</font>
    </td>
    <td>
    <input type=”text” size=”25″ maxlength=”100″ name=”BillCompany”>
    </td>
    </tr>
    <tr>
    <td>
    <font size=”-1″ face=”arial, helvetica”>Address:</font>
    </td>
    <td>
    <input type=”text” size=”40″ maxlength=”35″ name=”BillAddress1″>
    </td>
    </tr>
    <tr>
    <td>

    </td>
    <td>
    <input type=”text” size=”40″ maxlength=”35″ name=”BillAddress2″>
    </td>
    </tr>
    <tr>
    <td>
    <font size=”-1″ face=”arial, helvetica”>City:</font>
    </td>
    <td>
    <input type=”text” size=”25″ maxlength=”21″ name=”BillCity”>
    </td>
    </tr>
    <tr>
    <td>
    <font size=”-1″ face=”arial, helvetica”>State:</font>
    </td>
    <td>
    <select name=”BillState”>
    <option selected>
    <option value=”AL”>ALABAMA
    <option value=”AK”>ALASKA
    <option value=”AZ”>ARIZONA
    <option value=”AR”>ARKANSAS
    <option value=”CA”>CALIFORNIA
    <option value=”CO”>COLORADO
    <option value=”CT”>CONNECTICUT
    <option value=”DE”>DELAWARE
    <option value=”FL”>FLORIDA
    <option value=”GA”>GEORGIA
    <option value=”HI”>HAWAII
    <option value=”ID”>IDAHO
    <option value=”IL”>ILLINOIS
    <option value=”IN”>INDIANA
    <option value=”IA”>IOWA
    <option value=”KS”>KANSAS
    <option value=”KY”>KENTUCKY
    <option value=”LA”>LOUISIANA
    <option value=”ME”>MAINE
    <option value=”MD”>MARYLAND
    <option value=”MA”>MASSACHUSETTS
    <option value=”MI”>MICHIGAN
    <option value=”MN”>MINNESOTA
    <option value=”MS”>MISSISSIPPI
    <option value=”MO”>MISSOURI
    <option value=”MT”>MONTANA
    <option value=”NE”>NEBRASKA
    <option value=”NV”>NEVADA
    <option value=”NH”>NEW HAMPSHIRE
    <option value=”NJ”>NEW JERSEY
    <option value=”NM”>NEW MEXICO
    <option value=”NY”>NEW YORK
    <option value=”NC”>NORTH CAROLINA
    <option value=”ND”>NORTH DAKOTA
    <option value=”OH”>OHIO
    <option value=”OK”>OKLAHOMA
    <option value=”OR”>OREGON
    <option value=”PA”>PENNSYLVANIA
    <option value=”RI”>RHODE ISLAND
    <option value=”SC”>SOUTH CAROLINA
    <option value=”SD”>SOUTH DAKOTA
    <option value=”TN”>TENNESSEE
    <option value=”TX”>TEXAS
    <option value=”UT”>UTAH
    <option value=”VT”>VERMONT
    <option value=”VA”>VIRGINIA
    <option value=”WA”>WASHINGTON
    <option value=”DC”>WASHINGTON, D.C.
    <option value=”WV”>WEST VIRGINIA
    <option value=”WI”>WISCONSIN
    <option value=”WY”>WYOMING
    </select>

    <input type=”text” size=”10″ maxlength=”10″ name=”BillZip”>
    </td>
    </tr>
    <tr>
    <td colspan=2 align=center>
    <input type=”checkbox” name=”BillConfirm” selected> <font face=”arial, helvetica” size=”-2″>Send confirmation email via email</font>
    </td>
    </tr>

    <tr bgcolor=”#003399″>
    <td colspan=2 width=”100%” bgcolor=”#003399″>
    <b><font color=white size=”-1″ face=”arial, helvetica”>Shipping Information</font></b>
    <font color=white size=”-2″ face=”arial, helvetica”>
    [COLOR=Red][B](Check to use Billing Information: <input type=”checkbox” name=”copy”
    OnClick=”javascript:ShipToBillPerson(this.form);” value=”checkbox”>
    [/COLOR]
    )[/B]</td>
    </tr>
    <tr>
    <td>
    <font size=”-1″ face=”arial, helvetica”>First Name:</font></td>
    <td>
    <input type=”text” size=”15″ maxlength=”50″ name=”ShipFirst”>
    </td>
    </tr>
    <tr>
    <td>
    <font size=”-1″ face=”arial, helvetica”>Last Name:</font>
    </td>
    <td>
    <input type=”text” size=”15″ maxlength=”50″ name=”ShipLast”>
    </td>
    </tr>
    <tr>
    <td>
    <font size=”-1″ face=”arial, helvetica”>E-Mail:</font>
    </td>
    <td>
    <input type=”text” size=”15″ name=”ShipEmail”>
    </td>
    </tr>
    <tr>
    <td>
    <font size=”-1″ face=”arial, helvetica”>Company:</font>
    </td>
    <td>
    <input type=”text” size=”25″ maxlength=”100″ name=”ShipCompany”>
    </td>
    </tr>
    <tr>
    <td>
    <font size=”-1″ face=”arial, helvetica”>Address:</font>
    </td>
    <td>
    <input type=”text” size=”40″ maxlength=”35″ name=”ShipAddress1″>
    </td>
    </tr>
    <tr>
    <td>

    </td>
    <td>
    <input type=”text” size=”40″ maxlength=”35″ name=”ShipAddress2″>
    </td>
    </tr>
    <tr>
    <td>
    <font size=”-1″ face=”arial, helvetica”>City:</font>
    </td>
    <td>
    <input type=”text” size=”25″ maxlength=”21″ name=”ShipCity”>
    </td>
    </tr>
    <tr>
    <td>
    <font size=”-1″ face=”arial, helvetica”>State:</font>
    </td>
    <td>
    <select name=”ShipState”>
    <option selected>
    <option value=”AL”>ALABAMA
    <option value=”AK”>ALASKA
    <option value=”AZ”>ARIZONA
    <option value=”AR”>ARKANSAS
    <option value=”CA”>CALIFORNIA
    <option value=”CO”>COLORADO
    <option value=”CT”>CONNECTICUT
    <option value=”DE”>DELAWARE
    <option value=”FL”>FLORIDA
    <option value=”GA”>GEORGIA
    <option value=”HI”>HAWAII
    <option value=”ID”>IDAHO
    <option value=”IL”>ILLINOIS
    <option value=”IN”>INDIANA
    <option value=”IA”>IOWA
    <option value=”KS”>KANSAS
    <option value=”KY”>KENTUCKY
    <option value=”LA”>LOUISIANA
    <option value=”ME”>MAINE
    <option value=”MD”>MARYLAND
    <option value=”MA”>MASSACHUSETTS
    <option value=”MI”>MICHIGAN
    <option value=”MN”>MINNESOTA
    <option value=”MS”>MISSISSIPPI
    <option value=”MO”>MISSOURI
    <option value=”MT”>MONTANA
    <option value=”NE”>NEBRASKA
    <option value=”NV”>NEVADA
    <option value=”NH”>NEW HAMPSHIRE
    <option value=”NJ”>NEW JERSEY
    <option value=”NM”>NEW MEXICO
    <option value=”NY”>NEW YORK
    <option value=”NC”>NORTH CAROLINA
    <option value=”ND”>NORTH DAKOTA
    <option value=”OH”>OHIO
    <option value=”OK”>OKLAHOMA
    <option value=”OR”>OREGON
    <option value=”PA”>PENNSYLVANIA
    <option value=”RI”>RHODE ISLAND
    <option value=”SC”>SOUTH CAROLINA
    <option value=”SD”>SOUTH DAKOTA
    <option value=”TN”>TENNESSEE
    <option value=”TX”>TEXAS
    <option value=”UT”>UTAH
    <option value=”VT”>VERMONT
    <option value=”VA”>VIRGINIA
    <option value=”WA”>WASHINGTON
    <option value=”DC”>WASHINGTON, D.C.
    <option value=”WV”>WEST VIRGINIA
    <option value=”WI”>WISCONSIN
    <option value=”WY”>WYOMING
    </select>

    <input type=”text” size=”10″ maxlength=”10″ name=”ShipZip”>
    </td>
    </tr>
    <tr>
    <td colspan=2 align=center>
    <input type=”checkbox” name=”ShipConfirm” selected> <font face=”arial, helvetica” size=”-2″>Send confirmation email via email</font>
    </td>
    </tr>
    </table>
    </form>
    </center>

    <p><center>
    <font face=”arial, helvetica” size=”-2″>Free JavaScripts provided<br>
    by <a href=”http://javascriptsource.com”>The JavaScript Source</a></font>
    </center><p>

    <!– Script Size: 8.75 KB –>

    How can I change the script so that the functions are automatic, plus I would really like to use the script twice, or at least the function twice, once to complete the credit card if, and the second to insert the “state” and the name in another section of the same form?

    to post a comment
    JavaScript

    10 Comments(s)

    Copy linkTweet thisAlerts:
    @kelly23Nov 13.2005 — value="checkbox"> [/quote]

    This is incorrect. If you want it checked by default, just put checked
    inside the <input type="checkbox"> tag. If you don't want it checked by default, then leave it out.
    Copy linkTweet thisAlerts:
    @Mike_GauthorNov 13.2005 — Hi Kelly23

    What I'd ideally like to do is to get rid of the checkbox completly!
    Copy linkTweet thisAlerts:
    @kelly23Nov 13.2005 — Well the checkbox automatically makes the shipping address the same as the billing address. What exactly do you want to leave in there and what all do you want to remove?
    Copy linkTweet thisAlerts:
    @Mike_GauthorNov 13.2005 — Kelly

    What I'd like to remove is the bit of code:-

    Shipping Information</font></b>

    <font color=white size="-2" face="arial, helvetica">

    (Check to use Billing Information: <input type="checkbox" name="copy"

    OnClick="javascript:ShipToBillPerson(this.form);" value="checkbox"> )</td>

    So that the OnClick is automatic.

    Also I'd like to use it twice in the same form, I've tried various methods, duplicating the script but using different titles for the javascript, and using the BillName and BillState twice, but these stay blank and the rest of the fields are completed.

    Any suggesting to how I can accomplish this would be great.
    Copy linkTweet thisAlerts:
    @kelly23Nov 14.2005 — Hi,

    Sorry, but I'm not really following what you're trying to do. All the javascript functions do is assign the values from the form to a variable name. Unless you're going to do something else with those variable names (which I don't see in the script), I don't see the point.

    Also, if the billing address and the shipping address are automatically going to be the same, then there's no point in even having separate areas for both. Just have one section where they fill in name, address, city, state zip, etc.

    Usually the shipping info is blank so that if a customer wants to have an item shipped somewhere other than the billing address, they can enter that info when they come upon it; or as is the case where you have a checkbox to make the shipping info the same as the billing info, the customer is actually specifying that they want it shipped to the same address as the bill to. Another reason for this is that it allows for form validation to make sure that everything has been filled in by the customer. If you fill it in for them, and they really want it shipped to a different address, the form validation wouldn't catch it.

    Also, your form is named "billform", but in the script the form name is referenced as "form". That needs to be changed everywhere too, so before rewriting the script you need to rethink whether you really want to remove that checkbox and explain why you need to use the function twice.

    I just don't have a total picture of what you're trying to do.
    Copy linkTweet thisAlerts:
    @Mike_GauthorNov 14.2005 — Hi Kelly

    The form in question is a proposal form for life insurance, it is split into a number of sections.

    Section 1 - Personal Information: [COLOR=Red]Name, Address, City, State, Zip Code[/COLOR], date of birth, gender, etc.

    Section 2 - Underwriters Questions: A series of 18 questions with a YES/NO answer.

    Section 3 - Beneficiaries: Who will be paid under the terms of the policy.

    Section 4 - Payment Details: Standard Credit Card Info.

    Section 5 - Legal Bits: Fraud Notice and the other legal bits we are required to place by the Underwriters.

    Section 6 - Acceptance: The proposer inserts in boxes the data supplied exactly as it is supplied.

    Getting the data from Section 1 into Section 4 (Personal info to Credit Card Info) is no problem using the copy fields script. Plus the checkbox is perfectly acceptable here.

    But in Section 6, the State name needs to be inserted, plus the full name of the proposer needs to be inserted, plus I could have another checkbox here again without any problems, except of course call it some other name.

    The "Copy Fields Script" is great for the first part, automatically inserting the proposer full name and address in the appropiate boxes, but what it won't do is allow duplicates for the other areas.

    I've tried using two scripts in the header, the copy fields script as written (with the Ship changed to CC) and then a second script to copy only the name and state to Section 6 (ShipPerson changed to AcceptPerson), but in this case neither script works.

    Hope this has made the mud a bit clearer, and hopeful you so some other kind soul will supply an answer or a workaround for this minor but annoying problem
    Copy linkTweet thisAlerts:
    @kelly23Nov 14.2005 — 1.It sounds to me like you wouldn't even want a section for shipping info if this is a proposal for life insurance. (I'm confused. ? )

  • 2. But anyway, as far as duplicating the script, you need to:


  • a) Name the function something different like "function acceptanceInfo()" or whatever.

    b) Change all of the field names in the function to reflect the field names of the ones you're trying to fill in. For example if the name of the field in the Acceptance area is called "AcceptanceFirst" and you want to copy whatever is in BillFirst, then you would put in your function:

    formname.AcceptanceFirst.value = formname.BillFirst.value; //do this for each field you want to copy

    And the checkbox for this area would be something like:

    <input type="checkbox" name="copyAcceptance"

    OnClick="javascript:acceptanceInfo(this.form);">

    ... and in the function you'll want to see if the box is checked so you need to change the name of that field in the function from:

    if (formname.copy.checked)

    ... to ...

    if(formname.copyAcceptance.checked)

    Basically just make sure that you've changed all of the field names for everything.

    Hope that helps.
    Copy linkTweet thisAlerts:
    @Mike_GauthorNov 15.2005 — Hi Kelly

    After all this work on the form, I was going through a search option, and I discoved a script which will split the form into four or five separate forms using hidden fields to transfer the data to the final submission form.

    So I'm going to have a close look at this as it will enable the transfer the data through to the appropiate sections in the form
    Copy linkTweet thisAlerts:
    @kelly23Nov 15.2005 — Good choice. That form sounds way too long for one page.
    Copy linkTweet thisAlerts:
    @bfrordorfNov 22.2007 — I am trying to transfer data from one database on computer_A (address book) into a WEB-form to be filled out by users on a

    WEB-form running on WEB computer_B. All works fine when both pages are called from the same computer (same INETPUB but very

    different directory). I get a JScript error, however, whenever the two pages come from different computers. How can I solve

    this problem?


    data fetching page:

    function datasharing() {

    for (var i=4; i<22; i++)

    {

    input_id = "input_id_" + i;

    // alert( "name= " + parent.frames[2].document.all[input_id].name + " value= " + parent.frames[2].document.all

    [input_id].value );

    capture_id = "capture_id_" + i;

    capture_name = parent.frames[2].document.all[input_id].name;

    capture_value = parent.frames[2].document.all[input_id].value;

    // window.document.all[capture_id].value = capture_value; would be an alternative to fill the form

    parent.frames[3].document.all[capture_id].value = capture_value;

    capture_name = "";

    capture_value = "";

    }

    }

    on data source ASP-page:

    <% for i=0 to 25
    ' use a text string as the hidden input field ID not a numerical value in order to prevent JScript-problems
    ' name is the attribute name

    input_id = "input_id_" & i %>

    <input id="<%=input_id %>" type="hidden" name="<%=varArray(i) %>" value="<%=OptionArray(i,0) %>" >

    <% next %>


    with frame page:

    <frameset rows="*" framespacing="1">

    <frameset cols="114,*
    ">

    <frameset rows="*,81%">

    <frame name="contents" target="main" src="../pubs/info_index4.htm" scrolling="no">

    <frame name="contents1" src="../pubs/index1_pubs.asp" target="main">

    </frameset>

    <frameset rows="*
    ,65%">

    <!-- this works fine -->

    <frame id="top_frame" name="top_view" src="http://computer_A/author_project_view_keyword.asp" scrolling="auto">

    <frame id="bottom_frame" name="bottom_view" src="http://computer_A/project_datasharing_form.asp" scrolling="auto">

    <!-- but this does not work at all

    <frame id="top_frame" name="top_view" src="http://computer_A/author_project_view_keyword.asp" scrolling="auto">

    <frame id="bottom_frame" name="bottom_view" src="http://computer_B/project_datasharing_form.asp" scrolling="auto">

    -->

    </frameset>

    </frameset>


    Can somebody tell me how to get this simple piece of JScript to work when the top (data giving) frame-page comes from a

    different WEB-Server than the bottom (data-receiving) frame-page.
    ×

    Success!

    Help @Mike_G spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.18,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...