Jump to content

Xiang

Caspio Guru
  • Content Count

    75
  • Joined

  • Last visited

  • Days Won

    9

Posts posted by Xiang


  1. Hi Cameron,

     

    How are you?

     

    I think, you can use the following script:

    <SCRIPT LANGUAGE="JavaScript">
    function setDate()
    {
         var firstDateFieldName = "first";
         var secondDateFieldName = "second";
    
         firstDateFieldName = "InsertRecord" + firstDateFieldName;
         secondDateFieldName = "InsertRecord" + secondDateFieldName;
    
         var f_Date = document.getElementById(firstDateFieldName ).value;
         var first_Date = new Date(Date.parse(f_Date));
         var result_Date = new Date (first_Date.setMonth(first_Date.getMonth()+1));
    
         var d_month = result_Date.getMonth() + 1;
         if (d_month<10) {d_month = "0" + d_month;}
         var d_day = result_Date.getDate();
         if (d_day<10) {d_day = "0" + d_day;}
         var d_year = result_Date.getFullYear();
         var str_date = d_month + "/" + d_day + "/" + d_year;     
     
         document.getElementById(secondDateFieldName ).value = str_date;
    }
    document.getElementById("caspioform").onsubmit=setDate;   
    </SCRIPT>

    Let me know, if something doesn't work.


  2. Hi Cameron,

     

    How are you doing?

     

    If you want only to allow multi select, I think, the following code should help (enter it in the Footer of your Bulk Update screen):

    <SCRIPT LANGUAGE="JavaScript">
     /* "fieldName" is the variable name for the listbox type form element field. */
       var fieldName = "ENTER NAME OF YOUR FIELD";
       fieldName = "BulkEdit"+fieldName;  
    
       var x=document.getElementsByName(fieldName);
       x[0].multiple=true;
    
    </SCRIPT>

    Have a great day!


  3. Hello Logan,

     

    I checked with numbers also.

    Please note, that you should add a Header&Footer element, select the Footer element, click the Source button (or disable HTML Editor) and enter the code. If you enter the code before the field, script cannot work.

    Please also note, that the name of the field must be the exact same as in Table design.

     

    Please verify, that it's a Submission form. If it's a Details or Single/Update form, you can use the following code:

    <script type="text/javascript">
    function capitalize()
    {
    var fieldname = "YOUR_FIELD_NAME";
    fieldname = "EditRecord"+fieldname;
    confirmname = fieldname+"@Confirm";
    
    document.getElementById(fieldname).value = document.getElementById(fieldname).value.toUpperCase();
    document.getElementById(confirmname).value = document.getElementById(confirmname).value.toUpperCase();
    }
    document.getElementById('caspioform').onsubmit=capitalize;
    </script>

    Have a nice day!


  4. Hello Logan,

     

    How are you doing?

     

    I think, you can use the following script (don't forget to change "YOUR_FIELD_NAME" to the name of your field)

    <script type="text/javascript">
    function capitalize()
    {
    var fieldname = "YOUR_FIELD_NAME";
    fieldname = "InsertRecord"+fieldname;
    confirmname = fieldname+"@Confirm";
    
    document.getElementById(fieldname).value = document.getElementById(fieldname).value.toUpperCase();
    document.getElementById(confirmname).value = document.getElementById(confirmname).value.toUpperCase();
    }
    document.getElementById('caspioform').onsubmit=capitalize;
    </script>

    Fell free to ask, if anything does not work :)

    Have a good day!


  5. Hi George,

     

    How are you doing?

     

    I think, the following code can help (you can add a Header&Footer element to your Bulk Update form, select the Footer element, click the Source button and enter the code):

    <SCRIPT LANGUAGE="JavaScript">
    function concatenate()
    {
    var ResultFieldName = "Positions";
    
    var position1 = document.getElementById("BulkEditPosition1").value;
    var position2 = document.getElementById("BulkEditPosition2").value;
    
    var allpositions = position1 + position2;
    
    var inputName = "BulkEdit"+ ResultFieldName;
    var checkboxName = "Enable"+ inputName + "Ckb";
    document.getElementsByName(checkboxName )[0].checked=true;
    document.getElementById(inputName).value = allpositions;
    }
    
    var myButtons = document.getElementById("BulkUpdateForm").getElementsByTagName("input");
    var textValue = "";
    var UpdateButton;
    for(i=0;i<myButtons.length;i++)
       {
        textValue = myButtons[i].getAttribute("type");
        if(textValue=="button")
           {
            textValue = myButtons[i].getAttribute("value");
            if(textValue == "Update") UpdateButton = myButtons[i];
            }
        }
    UpdateButton.onmouseover=concatenate;
    </SCRIPT>

    It works with editable fields, and doesn't work with Hidden fields. Enter the name of your result field instead of "Positions".

     

    If you have any problems - feel free to ask, I'll be glad to help.

    Have a nice day!


  6. Hi codell,

     

    How are you doing?

     

    I think, it's better to create an App Parameter (for example, name it "RedirectURL" and enter the URL of your DataPage as value).

    Then add a Header&Footer element to your DataPages, select the Header element, click the Source button and enter the code like following:

    <SCRIPT LANGUAGE="JavaScript">
    var ValueParam='[@testParam]';
    var redirectURL='[@app:RedirectURL]';
    if(ValueParam.length==0) window.location.assign(redirectURL);
    </SCRIPT>

    Enter the name of your parameter instead of "testParam" and the name of your App Parameter instead of "RedirectURL".

     

    I'll be grateful, if you tell me if the code works or if any errors occur.

    Have a nice day!


  7. Hi Flosie,

     

    How are you doing?

     

    I think, you can use the following steps:

    Add a Virtual field and select a Hidden FormElement for it, then add the Header&Footer element, select the Footer, click the Source button and enter the code:

    <SCRIPT LANGUAGE="JavaScript">
    function emails()
    {
    var Regional_Manager = "Regional_Manager";
    var Manager = "Manager";
    var Submitter = "Submitter";
    
    Regional_Manager = "InsertRecord" + Regional_Manager;
    Manager = "InsertRecord" + Manager;
    Submitter = "InsertRecord" + Submitter;
    
    var email_Regional_Manager = document.getElementsByName(Regional_Manager)[0].value;
    var email_Manager = document.getElementsByName(Manager)[0].value;
    var email_Submitter = document.getElementsByName(Submitter)[0].value;
    
    var emailsList = email_Regional_Manager + ";" + email_Manager;
    if (email_Submitter.length>3) result_email = emailsList + ";" + email_Submitter;
    
    document.getElementById("cbParamVirtual1").value = emailsList;
    }
    document.getElementById("caspioform").onsubmit=emails;
    </SCRIPT>

    And then select your Virtual field as an address for your Acknowledgment email.

    Please note, if the Virtual Field is not the first, you should change the "cbParamVirtual1" to the correspond number, for example, to "cbParamVirtual3".

     

    Could you please let me know, if it works? :)

     

    Have a nice week-end!


  8. Hi wvantongeren,

     

    How are you doing?

     

    I think, you can use the following script:

    <SCRIPT LANGUAGE="JavaScript">
    function calculate()
    {
    var v_Werkuren = parseFloat(document.getElementById("InsertRecordWerkuren").value);
    var v_DWM_uren = parseFloat(document.getElementById("InsertRecorddwmuren").value);
    var v_55_uren = parseFloat(document.getElementById("InsertRecorduren55").value);
    var v_Ziekte_uren = parseFloat(document.getElementById("InsertRecordziekteuren").value);
    var v_Scholingsuren = parseFloat(document.getElementById("InsertRecordschooluren").value);
    var v_Onbetaalde_uren = parseFloat(document.getElementById("InsertRecordonbeturen").value);
    var v_totaaluren = v_Werkuren + v_DWM_uren + v_55_uren + v_Ziekte_uren + v_Scholingsuren - v_Onbetaalde_uren;
    document.getElementById("InsertRecordtotaaluren").value = v_totaaluren;
    }
    document.getElementById("caspioform").onsubmit=calculate;
    </SCRIPT>

    Could you please let me know, if the script works?

     

     

    Have a nice day!


  9. Hello Flosie,

     

    I have an idea. I'll try explaining it, but if I'm unclear - ask more details :)

    Add a Virtual field (it's should be Virtual1) and select the "Hidden" FormElement.

    Then for every checkbox, you can add a Virtual field, select the CheckBox FormElement, and enter an email address in the "Value when checked" field.

    Now you have a Hidden field and all your checkboxes and addresses.

    Add Header&Footer element, select the Footer, click the Source button, and enter the following code.

    If only one checkbox is present, you can use this code:

    <SCRIPT LANGUAGE="JavaScript">
    
    function create_list()
     {
       var emailsList = "myfirstEmail@mydomain.com";
       if(document.getElementById("cbParamVirtual2").checked) emailsList = emailsList + ";"+document.getElementById("cbParamVirtual2").value;
       document.getElementById("cbParamVirtual1").value = emailsList;
     }
     document.getElementById("caspioform").onsubmit=create_list;
    </SCRIPT>

    Please, enter a default address instead of "myfirstEmail@mydomain.com". For waht? If no checkboxes are checked, the DataPage will send an email to nobody, but it is a very bad practice, your Email can be marked as spam, if it sends emails to nobody.

     

    If you have two checkboxes, you cope the line

    if(document.getElementById("cbParamVirtual2").checked) emailsList = emailsList + ";"+document.getElementById("cbParamVirtual2").value;

    Paste it and change both "2" to "3":

    if(document.getElementById("cbParamVirtual3").checked) emailsList = emailsList + ";"+document.getElementById("cbParamVirtual3").value;

     

    Now the code is:

    <SCRIPT LANGUAGE="JavaScript">
    
    function create_list()
     {
       var emailsList = "myfirstEmail@mydomain.com";
    
       if(document.getElementById("cbParamVirtual2").checked) emailsList = emailsList + ";"+document.getElementById("cbParamVirtual2").value;
       if(document.getElementById("cbParamVirtual3").checked) emailsList = emailsList + ";"+document.getElementById("cbParamVirtual3").value;
    
       document.getElementById("cbParamVirtual1").value = emailsList;
     }
    
     document.getElementById("caspioform").onsubmit=create_list;
    </SCRIPT>

    And so on.

     

    The last thing - on the " Destination and Emails" screen, check "Acknowledgement email to email address submitted in form" and select Virtual1.

     

    Now emails should be send by condition.

     

    Please let me know if it works for you :)


  10. Hi AR,

     

    When a user submits a Form only one "onsubmit" event happens, so only first script works. You can combine both checks in one script:

    <script type="text/javascript">
    function capitalize()
    {
    var fieldname = "name_last";
    fieldname = "InsertRecord"+fieldname;
    
    var value = document.getElementById(fieldname).value;
    var newVal = '';
    val = value.split(' ');
    for(var c=0; c < val.length; c++)
       {
        newVal += val[c].substring(0,1).toUpperCase() + val[c].substring(1,val[c].length).toLowerCase() + ' ';
        }
    document.getElementById(fieldname).value = newVal;
    
    var fieldname2 = "name_first";
    fieldname2 = "InsertRecord"+fieldname2;
    
    var value2 = document.getElementById(fieldname2).value;
    var newVal2 = '';
    val2 = value2.split(' ');
    for(var c=0; c < val2.length; c++)
       {
        newVal2 += val2[c].substring(0,1).toUpperCase() + val2[c].substring(1,val2[c].length).toLowerCase() + ' ';
        }
    document.getElementById(fieldname2).value = newVal2;
    } 
    document.getElementById('caspioform').onsubmit=capitalize;
    </script>

    Does the code work now?


  11. Hi Sam,

     

    How are you doing?

     

    I think, you can insert the following code to your HTML Blocks:

    <script>
    var firstfield = '[@field:file1]';
    if(firstfield.length>0)
    document.write("<img src='[@field:file1/]' width=70%/>");
    else
    document.write("<img src='DEFAULT URL' width=70%/>");
    </script>

    Insert your field instead of both [@field:file1] .

    For me, it's better to use a Parameter picker and use the String format for the first line, and "File URL" for the "document.write" line.

     

    I will be glad to hear if the code works or help, if it does not :)


  12. Hi Cameron,

     

    How are you?

     

    I think, you can add an HTML Block to the Result page, disable an HTML Editor and enter the code like follows:

    <script>
    var checkbox='[@authfield:admin]';
    var hiddenValue="You cannot see this information";
    if (checkbox=="Yes") hiddenValue = '[@field:HiddenValue]';
    var line = "<span class='cbResultSetLabel'>Name </span><span class='cbResultSetData'>"+hiddenValue+"</span>";
    document.write(line);
    </script>

    Enter the name of you field in the Authentication DataSource instead of admin in the line "var checkbox='[@authfield:admin]';".

    Enter your message instead of "You cannot see this information".

    Enter the name of the field that contains value instead of HiddenValue in the line "if (checkbox=="Yes") hiddenValue = '[@field:HiddenValue]';"

     

    But I'm not sure that it's a secure enough for you, JavaScript is not a secure instrument.

     

    Have a good day!


  13. Hi Dev,

     

    You can use a "virtual" Submission form, so a user enters all data to Virtual fields. When the user clicks "Submit", parameters are passed to the second form.

    The second form is the "real" form, fields get parameters on load, and then you can disable all fields. If a user clicks Submit, the data are added to the table. You can add an HTML Block with the "Back" link, that will pass all parameters back to the Virtual form.

     

    Or you can use Update Forms. Something like

    http://howto.caspio.com/tech-tips-and-articles/common-customizations/how-to-create-a-multi-page-form/
    Then when a user clicks the "Submit", some checkbox is checked and the record is displayed.

     

    I hope it helps :)


  14. Hello Sean,

     

    How are you?

     

    I think, you can use the following code:

    <script>
    function calculate(){
    var selection = document.getElementsByName("InsertRecorddropdown")[0].value;
    
    var one = parseFloat(document.getElementById("InsertRecordone").value);
    var two = parseFloat(document.getElementById("InsertRecordtwo").value);
    var three = parseFloat(document.getElementById("InsertRecordthree").value);
    var four = parseFloat(document.getElementById("InsertRecordfour").value);
    var five = parseFloat(document.getElementById("InsertRecordfive").value);
    var six = parseFloat(document.getElementById("InsertRecordsix").value);
    var result = 0;
    
    switch(selection) {
        case "first":
            result = one * two;        
            break;
        case "second":
            result = three + four;        
            break;
        case "third":
            result = five * six + one;        
            break;
        default:
            result = one + two + three + four + five + six;        
    }
    document.getElementById("InsertRecordresult").value = result;
    }
    document.getElementsByName("InsertRecorddropdown")[0].onchange=calculate;
    
    </script>

    Please change names of fields (dropdown, one, result etc) and variants of selection (first, second, third). You can write more than one line of code after case "variant" and before "break;"

     

    Please feel free to ask.

     

     

    Happy New Year!


  15. Hi Dev,

     

    Welcome to the forum!

     

    It's rather strange workflow for me, but I think you can use the following idea:

    <script>
    document.write("<a href='URL?AppKey=somekeynumber&OrderID="+document.getElementById("InsertRecordOrderID").value+"'>Click me</a>");
    </script>

    Your script generates some ID and writes it to the OrderID field, is it correct?
    Then write the link in the HTML Block, use "document.getElementById("InsertRecordOrderID").value" instead of "[@field:OrderID]".

     

    Does it work for you?


  16. Hello Cameron,

     

    How are you doing?

     

    I think, you can use the following code:

    <script>
    var sheet = document.createElement('style');
         if((navigator.userAgent.indexOf("Opera") || navigator.userAgent.indexOf('OPR')) != -1 )
        {
            sheet.innerHTML = "input[type=text] {color: red !important;}"; //Opera
        }
        else if(navigator.userAgent.indexOf("Chrome") != -1 )
        {
            sheet.innerHTML = "input[type=text] {color: purple !important;}"; //Chrome
        }
        else if(navigator.userAgent.indexOf("Safari") != -1)
        {
             sheet.innerHTML = "input[type=text] {color: blue !important;}"; //Safari
        }
        else if(navigator.userAgent.indexOf("Firefox") != -1 )
        {
             sheet.innerHTML = "input[type=text] {color: red !important;}"; //Firefox
        }
        else if((navigator.userAgent.indexOf("MSIE") != -1 ) || (!!document.documentMode == true )) //IF IE > 10
        {
          sheet.innerHTML = "input[type=text] {color: orange !important;}"; //IE
        }  
        else
        {
           sheet.innerHTML = "input[type=text] {color: black !important;}"; //other
        }
    document.getElementsByTagName('head')[0].appendChild(sheet);
    document.head.appendChild(sheet);
        </script>

    If you want do not use any browser, you can add "//" before the line for this browser, for example:

    //sheet.innerHTML = "input[type=text] {color: red !important;}"; //Opera

     

    Also you can add more than one setting:

    sheet.innerHTML = "input[type=text] {color: red !important; background-color: black !important;}"; //Firefox
     

    Have a good day!


  17. HI Ar,

     

    How are you doing?

     

    I've rewrite the code, not it should work:

    <script type="text/javascript">
    function capitalize()
    {
    var fieldname = "YOUR_FIELD_NAME";
    fieldname = "InsertRecord"+fieldname;
     
    var value = document.getElementById(fieldname).value;
    var newVal = '';
    val = value.split(' ');
    for(var c=0; c < val.length; c++)
       {
        newVal += val[c].substring(0,1).toUpperCase() + val[c].substring(1,val[c].length).toLowerCase() + ' ';
        }
    document.getElementById(fieldname).value = newVal;
    } 
    document.getElementById('caspioform').onsubmit=capitalize;
    </script>

    Don't forget to change the YOUR_FIELD_NAME to the name of your field.

     

    Happy Christmas! ;)


  18. Thank you for this. Its almost there. 

     

    This add Six Months to current date. I would like to add Six Months to a date entered on a previous field on submit.

     

    Thank you Xiang

    I am sorry :rolleyes: Here the script code for the entered value:

    <SCRIPT LANGUAGE="JavaScript">
    
    function setDate()
    {
         var plusDays = 0;
         var plusMonths = 6;
         var plusYears = 0;
         var dateFieldName = "Name_Of_the_field_with_Entered_date";
         var fieldname = "Name_Of_the_field_with_Result_date";     
    
         dateFieldName = "InsertRecord" + dateFieldName;
         var entered_value = document.getElementById(dateFieldName).value;
         var myDate = new Date(entered_value);
         myDate.setDate(myDate.getDate()+plusDays);
         myDate.setMonth(myDate.getMonth()+plusMonths);
         myDate.setFullYear(myDate.getFullYear()+plusYears);
         var myMonth = myDate.getMonth() + 1;
         if (myMonth<10) {myMonth = "0" + myMonth;}
         var myDay = myDate.getDate();
         if (myDay<10) {myDay = "0" + myDay;}
         var myYear = myDate.getFullYear();
         var result = myMonth + "/" +  myDay + "/" + myYear;
         fieldname = "InsertRecord"+fieldname;
         document.getElementById(fieldname).value=result;
    }   
    
    document.getElementById("caspioform").onsubmit=setDate;
    </SCRIPT>

    Have a nice day!

×
×
  • Create New...