Jump to content

Js: Checkboxes For Multi-Optioned Entries


Recommended Posts

Hello IPV,

 

Welcome to Caspio forum!

 

If I understand correctly, you have one field that stores values.

So, you can

  1. Select the Hidden FormElement for the field that stores values.
  2. 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.
  3. 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.

Link to post
Share on other sites
  • 5 months later...

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...
×
×
  • Create New...