Jump to content

Xiang

Caspio Guru
  • Posts

    75
  • Joined

  • Last visited

  • Days Won

    9

Community Answers

  1. Xiang's post in Automatic Redirect Based On The Availability Of Required Parameters was marked as the answer   
    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!
  2. Xiang's post in Multi-Select Limit Selection was marked as the answer   
    Hi Elena,
     
    I've worked with your code. In my form the following code works:
    <script>  var v_Knowledge_New = "[@field:Knowledge_New]" ;  var o_Knowledge_New= document.getElementById("EditRecordKnowledge_New") ;  o_Knowledge_New.multiple = true ;  function f_listbox() {   if ( v_Knowledge_New.indexOf(",") > 0 ) {    for (var i=0 ; i < o_Knowledge_New.options.length; i++ ) {     if(o_Knowledge_New[i].value == v_Knowledge_New) {      o_Knowledge_New.remove(i);      break ;     }    }    var o_st = v_Knowledge_New.split(", ") ;    for (var j=0 ; j < o_st.length; j++) {     for (var i=0 ; i < o_Knowledge_New.options.length; i++ ) {      if(o_st[j]== o_Knowledge_New.options[i].value){       o_Knowledge_New.options[i].selected = true ;       break ;      }     }    }   }  }   window.onload = f_listbox ; function check_listbox() {    var maximum_selections = 5;    var MyListbox = document.getElementsByName("EditRecordKnowledge_New")[0];    var number_selections = 0;    for (var i=0; i<MyListbox.length; i++)    {       if (MyListbox.options[i].selected) number_selections++;     }    if (number_selections>maximum_selections)    {      alert("You can select only " + maximum_selections + " items");      return false     } } document.getElementById("caspioform").onsubmit=check_listbox; </SCRIPT> I've deleted a function, I think, it duplicates the functional and doesn't work in my account.
    Is it lost anything if this code is entered instead of the existed?
  3. Xiang's post in Disable Update Action On "single Record Update" Datapage was marked as the answer   
    Hi Alan,
     
    How are you? How's the weather in your city?
     
    I think, you can edit your Localization and add the following code to the message:
    <style> #Mod0EditRecord { display: none; } </style> Then the button is should be hidden, if the message is displayed.
    And the message should be displayed, if the message isn't displayed.
     
    I'll be grateful, if you tell me if the code works.

    Have a nice day!
  4. Xiang's post in Is It Possible To Preview An Image Before Uploading? was marked as the answer   
    Hi Cameron,
     
    How are you?
     
    I think, you can add a Header and Footer element, select the Footer element, click the Source button or disable the HTML Editor, and enter the following code:
    <script> document.getElementById("InsertRecordFIELDNAME").setAttribute("onchange","loadFile(event)");     var loadFile = function(event) {     var output = document.getElementById('output');     output.src = URL.createObjectURL(event.target.files[0]);   }; </script> Enter the name of your field instead of "FIELDNAME".
     
    And add an HTML Block, click the Source button or disable the HTML Editor, and enter the following code:
    <img id="output"/> Then the image will be displayed in full size.
    If you want to display with the fixed size, add width and height, for example:
    <img id="output" width="200px" height="100px" /> But in this case, all images will be displayed with these parameters. Sometimes it is horrible
     
    I'll be grateful, if you tell me if the code works.

    Have a nice day!
     
    And thank you to Nkron
  5. Xiang's post in Form Auto Submit And Calc Js was marked as the answer   
    Good morning Allen,

     

    How are you doing?

     

    In Java Script, "{" means "Start" and "}" means "Finish". So, if you want to do several actions in a function, I think, it's better don't write "Finish" and then "Start" again between them, the function doesn't execute any code after the "Finish" sign.

     

    In setTimeout('document.forms["caspioform"].submit()',0); }, "0" means how long a DataPage waits before auto submits. It's better to use "1000", at least "100" milliseconds, then you allow a DataPage to load and then autosubmit it.

     

    And if you want to call another function before autosubmit, you can write the same code but for another function:

    setTimeout('calculate()',500); }

     

    Then the whole code will be like:


    <SCRIPT LANGUAGE="JavaScript">
     
     function calculate()
     {
       var v_Current_Plan = parseFloat(document.getElementById("InsertRecordCurrent_Plan").value);
       var v_Current_Fee = parseFloat(document.getElementById("InsertRecordCurrent_Fee").value);
       var v_Rate= .08;
       var v_total  = (((v_Current_Plan * v_Rate) + v_Current_Plan) - (((v_Current_Plan * v_Rate) + v_Current_Plan) * v_Current_Fee));
       document.getElementById("InsertRecordCurrent_Plan").value = Math.round(v_total);

       var v_New_Plan = parseFloat(document.getElementById("InsertRecordNew_Plan").value);
       var v_New_Fee = parseFloat(document.getElementById("InsertRecordNew_Fee").value);
       var v_Rate= .08;
       var v_total  = (((v_New_Plan * v_Rate) + v_New_Plan) - (((v_New_Plan * v_Rate) + v_New_Plan) * v_New_Fee));
       document.getElementById("InsertRecordNew_Plan").value = Math.round(v_total);
     }
     
    if(document.getElementById("caspioform")) {
    document.getElementById("caspioform").style.display = 'none';
    setTimeout('calculate()',500);
    setTimeout('document.forms["caspioform"].submit()',1000); }
     
    </script>
    I'm learning the JavaScript now, so, I'll be grateful, if you tell me if the code works.

     

    Have a nice day!

×
×
  • Create New...