No announcement yet.

Multiple lines form - How to validate the sum of a numeric {field}

  • Filter
  • Time
  • Show
Clear All
new posts

  • Multiple lines form - How to validate the sum of a numeric {field}

    Hello, I'm creating an accounting form, multiple rows and I would liek to validate the form based on the sum of a numeric field {dare} and not the single row. The event ONVALIDATE is appling the code for each row inserted in the form multiple rows.

    I applied the following code to calculate the sum:

    onScriptInit - I create a global variable

    [somma] =0; (occur just once)

    onValidate - I add to somma each value of the column {dare} and it's working

    [somma] = [somma] + {dare}; (occur onetime for each row)

    Validation - I would like to validate like below code. I tried to insert on event ONAFTERINSSERTALL but it's registering the form and appearing the message "somma incorretta".

    if([somma] != 0){
    sc_error_message("somma incorretta");

    I want that the form is giving error and not recording the form if the sum is not equal to zero.

    Can you help me please?

    Thank you so much.

  • #2
    Can someone help me please with this?
    validate the sum of a column ( numeric field ) in a multiple rows form


    • #3
      use sc_redir(form_tblstatus_1.php); to redirect to same app. You wont see a error message then but no changes are made

      You can use ajax event aswell. onBlur you could use same code to inform user there is an error


      • #4
        Thank you so much for the tips.

        1) the code (below in red) on which event should I apply? Is there an event where to put the code that is running just one time after all rows are populated but before to record?

        if([somma] != 0){
        sc_error_message("somma incorretta");
        // I will try sc_redir as per your advice

        I tried on ONAFTERINSSERTALL and it's recording the wrong form and after executing the code.

        2) sc_redir(form_tblstatus_1.php) - instead of form_tblstatus_1 should I insert the name of my application?

        Thanks one million for your help!


        • #5
          GREAT THANK YOU SO MUCH FOR SOLUTION nonkelmike! With Sc_redirect it's not recording the form. I will work on the message for the user by myself!


          • #6
            sc_redir(form_tblstatus_1.php) is indeed the name of the application like like in your list of apps.


            • #7
              Thank you so much!


              • #8
                You can create a SQL in event on after insert for your SUM with a macro SC:

                SELECT SUM(dare) FROM MY_TABLE WHERE KEY = {YOUR_KEY};