2 // Copyright (C) 2010 Rod Roark <rod@sunsetsystems.com>
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
9 // This provides enhancement functions for the LBFfms visit form,
10 // "Functional Movement Screening". It is invoked by
11 // interface/forms/LBF/new.php.
13 // The purpose of this function is to create JavaScript for the <head>
14 // section of the page. This in turn defines desired javaScript
17 function LBFfms_javascript() {
20 echo "// Array identifying the numeric '0-3' fields.
32 echo "// A numeric '0-3' field has changed.
33 function fms_numeric_changed(e) {
34 var f = document.forms[0];
35 // Check if the entry is a valid digit.
36 var val = parseInt(e.value);
37 if (isNaN(val) || val < 0 || val > 3) {
41 // Propagate values to the read-only second column.
43 var namepref = name.substring(0, name.length - 2); // removing the '_1'.
44 var namelr = namepref.substring(namepref.length - 2, namepref.length);
45 var name2 = namepref; // this will be the target
46 // If this is a Left or Right field, we propagate the lower of the two
47 // to the Left row in column 2.
49 var tmp = parseInt(f[namepref.substring(0,namepref.length-1) + 'r_1'].value);
50 if (!isNaN(tmp) && tmp < val) val = tmp;
52 else if (namelr == '_r') {
53 name2 = namepref.substring(0,namepref.length-1) + 'l';
54 var tmp = parseInt(f[namepref.substring(0,namepref.length-1) + 'l_1'].value);
55 if (!isNaN(tmp) && tmp < val) val = tmp;
57 f[name2 + '_2'].value = val;
58 // Tally up the propagated values.
60 for (var i = 0; i < fms_numeric.length; ++i) {
61 var val = parseInt(f['form_' + fms_numeric[i] + '_2'].value);
62 if (!isNaN(val)) sum += val;
64 f.form_total.value = sum;
70 // The purpose of this function is to create JavaScript that is run
71 // once when the page is loaded.
73 function LBFfms_javascript_onload() {
75 var f = document.forms[0];
76 for (var i = 0; i < fms_numeric.length; ++i) {
77 var namepref = 'form_' + fms_numeric[i];
78 f[namepref + '_2'].readOnly = true;
79 var ename = namepref + '_1';
80 f[ename].onchange = function () { fms_numeric_changed(this); };
81 var namelr = namepref.substring(namepref.length - 2, namepref.length);
83 ename = namepref.substring(0,namepref.length-1) + 'r_1';
84 f[ename].onchange = function () { fms_numeric_changed(this); };
87 f.form_total.readOnly = true;