JanineB Posted March 3, 2022 Report Share Posted March 3, 2022 Can anyone provide me with a solution to my case? I want to automatically copy a value in a text field when the checkbox or radio button is selected. Is this possible? Quote Link to comment Share on other sites More sharing options...
Kurumi Posted March 3, 2022 Report Share Posted March 3, 2022 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: 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: 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: Hope it helps! JanineB 1 Quote Link to comment Share on other sites More sharing options...
JanineB Posted March 3, 2022 Author Report Share Posted March 3, 2022 Thank you @Meekeee! Kurumi 1 Quote Link to comment Share on other sites More sharing options...
SangK Posted March 3, 2022 Report Share Posted March 3, 2022 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.