Populate value from one field to another on change

I am trying to duplicate text on change from on drop-down menu to a plain text box.

stage

I am trying this with no luck. What am I missing?

//This duplicates Stage to ROStage

var input1 = fd.field('Stage');
var input2 = fd.field('ROStage');

fd.field('Stage').$on('change' function() {
input2.value = input1.value;
});

Hello @shedev,

The comma is missing in the code after 'change', please find the updated code below.

//This duplicates Stage to ROStage

var input1 = fd.field('Stage');
var input2 = fd.field('ROStage');

fd.field('Stage').$on('change', function() {
input2.value = input1.value;
});
1 Like

Is there a data type requirement for this to work properly?

I have tried the above code and my ROStage field is not populating.

Some background:

  • This is an "Edit" form

  • List column "Stage" is a dropdown SharePoint Choice field

  • "Stage" has a default value of "Initial Development"

  • Tried: "ROStage" as a Plumsail form Plain Text box

  • Tried: "ROStage" as a dropdown SharePoint Choice field

  • Tried: "ROStage" as a ReadOnly field

  • "Stage" is a dropdown SharePoint Choice field that gets hidden in a Staff Only Accordion

  • I want all users to be able to see the Stage the workflow is in presently. I thought that if a staff member updated the Stage in the hidden accordion, it would be nice for the ReadOnly field to update as well, to display progress of the workflow.

There are other elements in each of the accordions. I have removed them from view for this example.

Some code snippets, other than your suggestion, I have found and have been trying to adapt are:

fd.spRendered(function() {
//Set field value with the value from the parent on form load
fd.field('ROStage').value = fd.field('Stage').value;

        function onchange() {
        //Since you have JQuery, why aren't you using it?
        var box1 = $('#Stage');
        var box2 = $('ROStage');
        box2.val(box1.val());
    }
    $('Stage').on('change', onchange);
});
function change(){
            var src= document.getElementById("sourceTextField");
            var dest= document.getElementById("destinationTextField");
            dest.value=src.value;
        }

@shedev,

Depend on the field type there are different methods of getting and setting the values. Please find more information in the documentation here and in the Manipulate fields dynamically article.

In case you need to populate the text field with the value from the drop-down filed when the value is chaged, you can use this code:

fd.spRendered(function() {

    fd.field('Stage').$on('change', function() {
    	fd.field('ROStage').value = fd.field('Stage').value;
    });
    
});

Thank you - this made all the difference!

1 Like