Jump to content

Copy value in another field when criteria met


Recommended Posts

Hi @JanineB - yes this is possible. You have two options to do this.

1. Standard Feature by using Calculated Value. You can use this if you don't want your second field to be editable.

Steps:
Change the Form Element of your second field to Calculated Value. In the Formula, you can have a CASE WHEN statement

In my example, I have Virtual Fields which is either a checkbox or radio button. 

Here's the formula:

CASE WHEN '[@cbParamVirtual1]' = 'Y'
THEN [@field:FIELD1]
WHEN '[@cbParamVirtual2]' = 'Yes'
THEN [@field:FIELD1]
ELSE
''
END

This formula means that if my checkbox = Y THEN copy the value from the first field. Same as the radio button, if the value = Yes THEN copy the value. ELSE - it will show nothing.

Result:

image.png

image.png

If you only have the radio button then you can have this formula:

CASE WHEN '[@RadioButtonField]' = 'Yes'
THEN [@field:FIELD1]
ELSE
''
END

2. By using custom JavaScipt/JS to show it in the text field so it can be editable. You can insert these codes in the Footer. Make sure to disable the HTML Editor in the Advanced Tab.
 

Radio Button:

<script type="text/javascript">
document.addEventListener('DataPageReady', function (event) {
 
var radios = document.getElementsByName("RADIOBUTTONFIELD");

  //get radiobutton values on every change
  for(i = 0; i < radios.length; i++) {
        if(radios[i].addEventListener('change', function() {
          
            //copy record from text field 1 to text field 2
          if (this.value == 'Yes') {
              document.getElementById("InsertRecordFIELD2").value = document.getElementById("InsertRecordFIELD1").value; 
          }

            else {
              
              //If No is selected then blank
              document.getElementById("InsertRecordFIELD2").value = null;
            }
        }));
    
}

});

</script>

Result:

image.pngimage.png

 

Checkbox:

<script>

document.querySelector("input[name='CHECKBOX']").addEventListener("change", function test(){

//checks the checkbox if yes
if(document.querySelector("input[name='CHECKBOX']").checked=true){

//copy the text
 document.getElementById("InsertRecordFIELD2").value = document.getElementById("InsertRecordFIELD1").value; 
}

});

</script>

Result:

image.png

Hope it helps!

Link to comment
Share on other sites

Thanks for the help, I am trying to accomplish the same task inside multi-page Datapages.  I try copying your code and made the necessary changes but it didn't work.

So, I created a test table with 4 fields to replicate your example, I then  copied the code (tried both Radio and Check box) inside the footer with HTML turned off, but it's still not working.  I feel like code is not be executed at all by Caspio.

Any thoughts would be greatly appreciated

Sang

Copy Test.jpg

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...