/*----- signature: allFilled: void -> Boolean purpose: expects nothing, returns true if the three textfields in three-value-form.php have values and the 2nd textfield has a numeric value; otherwise, it returns false AND complains in the paragraph whose id="errors" by: Sharon Tuttle last modified: 2016-04-11 -----*/ function allFilled() { var value1Field = document.getElementById("value1"); var value2Field = document.getElementById("value2"); var value3Field = document.getElementById("value3"); // these are all input elements of type "text" -- // they have a value attribute representing // what is in that element at that point var val1 = value1Field.value; var val2 = value2Field.value; var val3 = value3Field.value; var result = true; var errorsPara = document.getElementById("errors"); // complain and return false if any fields are empty if ( (! val1.trim() ) || (! val2.trim() ) || (! val3.trim() ) ) { errorsPara.innerHTML = "MUST fill in ALL " + "textfields before submit! (white space " + "won't do)"; result = false; } // if all fields are filled (with something non-white- // space), then make sure 2nd field is numeric // some JavaScript functions: // isNaN - returns true if its argument is // not a number // parseFloat - expects a string, tries to // return the corresponding floating-point // number else if (isNaN(parseFloat(val2)) || (parseFloat(val2) != val2)) { errorsPara.innerHTML = "2nd textfield MUST contain " + "ONLY a number!"; result = false; } return result; }