IPV Posted February 1, 2016 Report Share Posted February 1, 2016 Dear All,Would you please advice for next:Is it possible to collect Data with next checkboxes and write them into one field in the table? I do believe that some special JavaScript needed here.Many thanks in advance. Quote Link to comment Share on other sites More sharing options...
Jan Posted February 1, 2016 Report Share Posted February 1, 2016 Hello IPV, Welcome to Caspio forum! If I understand correctly, you have one field that stores values. So, you can Select the Hidden FormElement for the field that stores values. Add a Virtual field, select the "Checkbox" element and enter your values, for example, "Math", to "Display Text" and "Value when checked" fields. Add as many virtual fields as you want. Add Header&Footer element, select the Footer element, click the Source button and enter the following script: (please enter the name of your field that stores values instead of "text"; enter the numbers of first and last Virtual fields in the group of checkboxes, in my case the first one is VirtualField1 and the last one is VirtualField3) <SCRIPT LANGUAGE="JavaScript"> function concatenate() { var Resultfieldname = "text"; var firstVirtual = 1; var lastVirtual = 3; var ResultString = ""; var virtualFieldName = ""; for (i=firstVirtual ;i<=lastVirtual; i++) { virtualFieldName = "cbParamVirtual"+i; if (document.getElementById(virtualFieldName).checked) ResultString = ResultString + "," + document.getElementById(virtualFieldName).value; } Resultfieldname = "InsertRecord"+Resultfieldname; if (ResultString.length>0) ResultString = ResultString.substr(1); document.getElementById(Resultfieldname ).value = ResultString; } document.getElementById("caspioform").onsubmit=concatenate; </SCRIPT> If you have more than one block, you can add blocks like: (please enter the name of your second field that stores values instead of "new"; enter the numbers of first and last Virtual fields in the second group of checkboxes, in my case the first one is VirtualField4 and the last one is VirtualField6) Resultfieldname = "new"; firstVirtual = 4; lastVirtual = 6; ResultString = ""; virtualFieldName = ""; for (i=firstVirtual ;i<=lastVirtual; i++) { virtualFieldName = "cbParamVirtual"+i; if (document.getElementById(virtualFieldName).checked) ResultString = ResultString + "," + document.getElementById(virtualFieldName).value; } Resultfieldname = "InsertRecord"+Resultfieldname; if (ResultString.length>0) ResultString = ResultString.substr(1); document.getElementById(Resultfieldname ).value = ResultString; Then the whole script will be like: <SCRIPT LANGUAGE="JavaScript"> function concatenate() { var Resultfieldname = "text"; var firstVirtual = 1; var lastVirtual = 3; var ResultString = ""; var virtualFieldName = ""; for (i=firstVirtual ;i<=lastVirtual; i++) { virtualFieldName = "cbParamVirtual"+i; if (document.getElementById(virtualFieldName).checked) ResultString = ResultString + "," + document.getElementById(virtualFieldName).value; } Resultfieldname = "InsertRecord"+Resultfieldname; if (ResultString.length>0) ResultString = ResultString.substr(1); document.getElementById(Resultfieldname ).value = ResultString; //second block Resultfieldname = "new"; firstVirtual = 4; lastVirtual = 6; ResultString = ""; virtualFieldName = ""; for (i=firstVirtual ;i<=lastVirtual; i++) { virtualFieldName = "cbParamVirtual"+i; if (document.getElementById(virtualFieldName).checked) ResultString = ResultString + "," + document.getElementById(virtualFieldName).value; } Resultfieldname = "InsertRecord"+Resultfieldname; if (ResultString.length>0) ResultString = ResultString.substr(1); document.getElementById(Resultfieldname ).value = ResultString; } document.getElementById("caspioform").onsubmit=concatenate; </SCRIPT> I hope, it helps. Please feel free to ask if anything is unclear. TWIRED 1 Quote Link to comment Share on other sites More sharing options...
wgalliance Posted July 19, 2016 Report Share Posted July 19, 2016 I need this function for one of my datapages but the difference is that I have an update form which needs to store the separate checkbox fields so I cannot use virtual fields. Can this script be used with actual checkbox fields rather than virtual fields? TWIRED 1 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.