Announcement

Collapse
No announcement yet.

How to create AJAX events to sum three fields in the form

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to create AJAX events to sum three fields in the form

    I have created form using script case.

    Please tell me how to sum three form fields and it should show results on fourth field.
    I know this can be done by ajax on change event.

    can any one tell me the coding for oncahnge event to sum three fields and results should show in fourth fields

    Am using mysql database

    Thanks in advance

  • #2
    Re: How to create AJAX events to sum three fields in the form

    Hi rajuleo,

    I would do the following:
    1. create a new PHP method (look on the left under Programming) called SumFields() or something
    2. SumFields() would have the line {field4) = {field1} + {field2} + {field3};
    3. Under Ajax Events, click New Ajax Event, and create an event for each of the fields 1 - 3
    4. In those events, call SumFields()

    That should do the trick.

    Take care,
    sifa

    Comment


    • #3
      Re: How to create AJAX events to sum three fields in the form

      Thanks sifa

      Comment


      • #4
        Re: How to create AJAX events to sum three fields in the form

        Thanks for the input....tried the instructions....here is what I have...

        php method:

        function SumQuantity()
        {
        {txt_totalitems} = {wdiS} + {wdiM} + {wdiL} + {wdiXL} + {wdi2XL} + {wdi3XL} + {wdiOther};
        }

        Ajax Event:
        SumQuantity();

        Recompile and get the following error:
        Fatal error: Cannot redeclare form_workorderitems_apl::SumQuantity() in C:\Program Files

        Am I missing something?
        Thanks

        Comment


        • #5
          Re: How to create AJAX events to sum three fields in the form

          If the generating does not work, by an unknown reason at the moment, have you tried to put the line with the sum in the ajax_event php field. Instead of the calling of the php method?

          If the onchange does not work as you want, I had something like that in the past, I suggest to use the blur event, which is closebto the onchange ...

          Comment


          • #6
            Does anyone else have any advice about how to go about this? I am needing the same thing: an integer "Total" field on a form which is populated as the user adds integers to other fields. (I have 36 fields to total on this form...yuck.)

            I tried the above and didn't get anything to happen. Not sure if I'm setting the AJAX events properly. Here's what I'm doing:

            1) Creating a PHP Method called "sumContacts()"
            2) function sumContacts() {
            {total_contacts} = {wma} + {wfa} + {wmy} + {wfy} ; //...... 32 more fields
            }
            3) Create AJAX event
            4) Select wma as the field to create the event
            5) Select OnBlur as the event
            6) Select wma as the field that will passed as parameters
            7) put sumContacts(); in the wma_onBlur code block
            8) repeat 3 - 7 with the other fields

            Nothing happens when I go to my form and start putting in numbers.

            What am I doing wrong? Thanks in advance.

            Comment


            • #7
              Hi,
              you did a little too much.
              First, delete line 1 and 3 in your sumContats() method (step two in your list), you just need the '{total_contacts} = ...' there.
              Second, you don't need to pass any parameter. So step 6 is not necessary.

              That should do it.

              jsb

              Comment


              • #8
                Hey thanks a bunch. I'll give this a try!

                Comment

                Working...
                X