Using JavaScript To Pass Field Value To Another Field

Olivian Stoica

by Olivian Stoica

This is a tutorial where I am going to show you how you can pass the user input value from one field to another on the same online form by using a Javascript code.

JavaScript can be used in many ways on your forms to extend their capabilities and control interactions. If you are new to JavaScript or don’t have much technical skills, you don’t need to worry, because I am going to provide you the entire code and specify what you need to change on your end.

Firstly, what does this code do exactly? Well, if someone starts completing your online form and gets to fill a particular field, the input will be automatically copied to another field. This works great for forms where the user has to provide the same information more than once.

Check out this sample. Fill in the first field and move towards the second one:

The code is triggered once you have moved from the first field.

Keep in mind that for this workaround to work on your 123FormBuilder web form, you’ll need to enable the JavaScript feature on your form, which is located in the Advanced section.

Step 1. Create Your JavaScript file

Open your notepad and copy the code provided below:

var demo123CF_CopyFieldValue = new function() {
    var self = this;

    this.errorMessage = '';

    this.id123cf = '#id123-control';
    this.fieldOrigin = '';
    this.fieldDestination = '';

    this.setFieldOriginID = function ( fieldId ) {
        this.fieldOrigin = fieldId;

    this.setFieldDestinationID = function ( fieldId ) {
        this.fieldDestination = fieldId;

    this.init = function () {

    this.validateData = function () {
            this.errorMessage = 'Invalid origin field';
            this.errorMessage = 'Invalid destination field';

        return this.errorMessage == '';

    this.updateDestinationValue = function (){
        if(!this.validateData()) {


    this.setOnChange = function () {
        if(!this.validateData()) {

        //change event from start date to be copied to end date
        $(this.id123cf+this.fieldOrigin).change(function() {


$( document ).ready(function() {

Now you will need to adjust the code a bit. You will need the ID of the field from where you are going to pass its input value and the ID of the field where the input value is passed.

This is the function that will pass/copy the value from the first field:


This is the function that will paste the copied value to the second field:


Now you need to replace field-id-1 and field-id-2 with the respective IDs of your field inputs.

What you need to do in this step is enable developer tools in your browser. You can check on how to do this on Google Chrome, Mozilla Firefox, Safari, Opera and IE.

Next, view your online form from a visitor’s perspective and right-click the field input from where you want to pass its value. An option that allows you to inspect elements should appear in the context menu. Click it to continue.

using inspect element to pass user input from one field to another on the form

Look for the input tag and copy the field ID that appears after “control”. Read our blog article on how to inspect your form fields for more details.

pass user value from field to another by using the field ID

Now get back to your notepad where the JavaScript code is located. Add your field ID by replacing the old one within the function:

demo123CF_CopyFieldValue.setFieldOriginID('field input ID goes here'); 

Do the same for the second function, but replace the ID with that of the second field, instead.

demo123CF_CopyFieldValue.setFieldDestinationID('field input ID goes here');

Finally, save your notepad document as a JavaScript file. You can do this easily by providing the .js extension next to the name. For example passvalue.js

Step 2. Apply The JavaScript On The Form

At 123FormBuilder, in order to add a custom JavaScript to your web form, you will need to go the Settings → Advanced section and click the Form tab. There, tick the option Add a JS script to your form and provide the URL of your script.

passing value from one field input to another with javascript url on form

If you don’t have a server where you can upload the JS file, try GitHub. It’s a free hosting platform for developers where they can upload all sorts of scripts. Create an account on GitHUb and upload your .js file there. Obtain the URL to your script and provide it in the JS URL box on 123FormBuilder.

[Update]: The URL of your Javascript file must be hosted on a secure (HTTPS) environment.

If you want to pass field input values from one web form to another, 123FormBuilder provides a great feature that makes it possible without coding. Read our documentation about it.

And there you have it! You can now test your form and see the results. If you require assistance, don’t hesitate to contact our customer support specialists.


  1. This documentation needs updating. the ID tag is no longer found in the INPUT field. Please someone correct this post and update it. I keep getting your support staff sending me links to this page.

Leave a comment

Your email address will not be published. Required fields are marked *

You love forms as much as we do?

Then share your form story with us! We will read all the submitted cases and reach out the selected ones for further details. The chosen ones will have a case study created and will be featured in our blog, newsletter and social media channels.