This topic is locked
[SOLVED]

 Problem getting calculated form/fields to work

4/21/2015 8:22:52 PM
PHPRunner General questions
M
mfriend author

Hi Support:

I'm trying to set up a couple of calculated fields that are to be populated by running a JavaScript function. I'm trying to follow the example at: http://xlinesoft.com/articles/how_to_use_calculated_fields.htm
I my form I have 3 fields: one that the user enters a number, and the other two are calculated from that.
The code for the 3 fields are:

<th class="rnr-gridfieldlabel rnr-field-number"> <span data-order="aSOIL_MOIST_0_1" id="order_SOIL_MOIST_0_1_1" name="order_SOIL_MOIST_0_1_1" data-href="FARM_FIELD_SCOUTING_REPORT_list.php?orderby=aSOIL_MOIST_0_1" class="rnr-orderlink"> Soil Moisture 0 to 1 FT </span> </th>
<th class="rnr-gridfieldlabel rnr-field-number"> <span data-order="aSOIL_MOIST_1_2" id="order_SOIL_MOIST_1_2_1" name="order_SOIL_MOIST_1_2_1" data-href="FARM_FIELD_SCOUTING_REPORT_list.php?orderby=aSOIL_MOIST_1_2" class="rnr-orderlink"> Soil Moisture 1 to 2 FT </span> </th>
<th class="rnr-gridfieldlabel rnr-field-number"> <span data-order="aSOIL_MOIST_2_3" id="order_SOIL_MOIST_2_3_1" name="order_SOIL_MOIST_2_3_1" data-href="FARM_FIELD_SCOUTING_REPORT_list.php?orderby=aSOIL_MOIST_2_3" class="rnr-orderlink"> Soil Moisture 2 to 3 FT </span> </th>



I'm assuming that the three field names I need to use are the ID's:

  1. order_SOIL_MOIST_0_1_1
  2. order_SOIL_MOIST_1_2_1
  3. order_SOIL_MOIST_2_3_1
    So the user would enter a number in box 1 (ID of order_SOIL_MOIST_0_1_1) of say .87
  4. Then number 2 (order_SOIL_MOIST_1_2_1) would be something like 80% of box 1.
  5. Then number 3 (order_SOIL_MOIST_2_3_1) would be something like 70% of box 1.
    The JavaScript I put into the "JavaScript on Load" Event for the add page is:

var ctrlorder_SOIL_MOIST_0_1_1 = Runner.getControl(pageid, 'order_SOIL_MOIST_0_1_1');

var ctrlorder_SOIL_MOIST_1_2_1 = Runner.getControl(pageid, 'order_SOIL_MOIST_1_2_1');

var ctrlorder_SOIL_MOIST_2_3_1 = Runner.getControl(pageid, 'order_SOIL_MOIST_2_3_1');

function func() {

ctrlorder_SOIL_MOIST_1_2_1.setValue(0.80*(+ctrlorder_SOIL_MOIST_0_1_1.getValue()))

ctrlorder_SOIL_MOIST_2_3_1.setValue(0.70*(+ctrlorder_SOIL_MOIST_0_1_1.getValue()))

};

ctrlorder_SOIL_MOIST_0_1_1.on('keyup', func);


I'm trying to follow your example and its not working but I'm probably making some stupid mistake since I know little JavaScript.
Any help would be appreciated.
Thanks,
Matthew

W
wpl 4/22/2015



Hi Support:

I'm trying to set up a couple of calculated fields that are to be populated by running a JavaScript function. I'm trying to follow the example at: http://xlinesoft.com/articles/how_to_use_calculated_fields.htm
I my form I have 3 fields: one that the user enters a number, and the other two are calculated from that.
The code for the 3 fields are:

<th class="rnr-gridfieldlabel rnr-field-number"> <span data-order="aSOIL_MOIST_0_1" id="order_SOIL_MOIST_0_1_1" name="order_SOIL_MOIST_0_1_1" data-href="FARM_FIELD_SCOUTING_REPORT_list.php?orderby=aSOIL_MOIST_0_1" class="rnr-orderlink"> Soil Moisture 0 to 1 FT </span> </th>
<th class="rnr-gridfieldlabel rnr-field-number"> <span data-order="aSOIL_MOIST_1_2" id="order_SOIL_MOIST_1_2_1" name="order_SOIL_MOIST_1_2_1" data-href="FARM_FIELD_SCOUTING_REPORT_list.php?orderby=aSOIL_MOIST_1_2" class="rnr-orderlink"> Soil Moisture 1 to 2 FT </span> </th>
<th class="rnr-gridfieldlabel rnr-field-number"> <span data-order="aSOIL_MOIST_2_3" id="order_SOIL_MOIST_2_3_1" name="order_SOIL_MOIST_2_3_1" data-href="FARM_FIELD_SCOUTING_REPORT_list.php?orderby=aSOIL_MOIST_2_3" class="rnr-orderlink"> Soil Moisture 2 to 3 FT </span> </th>



I'm assuming that the three field names I need to use are the ID's:

  1. order_SOIL_MOIST_0_1_1
  2. order_SOIL_MOIST_1_2_1
  3. order_SOIL_MOIST_2_3_1
    So the user would enter a number in box 1 (ID of order_SOIL_MOIST_0_1_1) of say .87
  4. Then number 2 (order_SOIL_MOIST_1_2_1) would be something like 80% of box 1.
  5. Then number 3 (order_SOIL_MOIST_2_3_1) would be something like 70% of box 1.
    The JavaScript I put into the "JavaScript on Load" Event for the add page is:

var ctrlorder_SOIL_MOIST_0_1_1 = Runner.getControl(pageid, 'order_SOIL_MOIST_0_1_1');

var ctrlorder_SOIL_MOIST_1_2_1 = Runner.getControl(pageid, 'order_SOIL_MOIST_1_2_1');

var ctrlorder_SOIL_MOIST_2_3_1 = Runner.getControl(pageid, 'order_SOIL_MOIST_2_3_1');

function func() {

ctrlorder_SOIL_MOIST_1_2_1.setValue(0.80*(+ctrlorder_SOIL_MOIST_0_1_1.getValue()))

ctrlorder_SOIL_MOIST_2_3_1.setValue(0.70*(+ctrlorder_SOIL_MOIST_0_1_1.getValue()))

};

ctrlorder_SOIL_MOIST_0_1_1.on('keyup', func);


I'm trying to follow your example and its not working but I'm probably making some stupid mistake since I know little JavaScript.
Any help would be appreciated.
Thanks,
Matthew


Matthew,
you should use the "real" fieldnames in your JavaScript code. "order_SOIL_MOIST_xxx" are the table headings on the list page used for sorting the table.

The real fieldnames I would expect to be SOIL_MOIST_0_1_1,SOIL_MOIST_1_2_1, and SOIL_MOIST_2_3_1.
Just my 2 cents

Sergey Kornilov admin 4/22/2015

wpl is correct, do not use some IDs, use real field names.
And this specific scenario (incorrect field name leading to Javascript error) is described in troubleshooting guide at http://xlinesoft.com/phprunner/docs/troubleshooting_javascript_errors.htm

M
mfriend author 4/22/2015

Thank you for your help WPL and Sergey:
I was attempting to get the field names from right clicking on the add page and looking at the source code. One of my problems I discovered is that I had the add page set as a 'pop-up' or modal version. Once I changed it to the 'normal' or non-modal version of the add page I was able to see what WPL was talking about:

<div data-fieldname="SOIL_MOIST_1_2" class="rnr-field style1 ">


Once I plugged the actual field names in it worked fine. At least next time I know.
I appreciate the help... I've printed off the JavaScript troubleshooting section from the manual and watched the video also on troubleshooting.
Matthew
P.S. Sergey: Is it almost time for the 8.1 beta?