// $Id: formvalidate.js,v 1.14 2006/05/03 18:05:28 jseverson Exp $ // /********************************************************************** chkMandatory: check mandatory fields on the form objForm parameters: objForm - form reference pre-requisites: aMandatory - array of fields for which mandatory evaluation should be done Depends on: alltrim() which is a function of string.js library aMandatory should be defined on each HTML page format of aMandatory: aMandatory[] = new Array(, , ); : message to be displayed on mandatory check failure (NOTE: system dispalyes " is mandatory") : "TEXT", "RADIO" : name of the field where focus should be placed on mandatory check failure. if this is "" then focus is place on **********************************************************************/ var aMandatory = new Array(); function chkMandatory(objForm) { for (var iLoop in aMandatory) { var strVal; strVal = ""; if (aMandatory[iLoop][1] == "Text") strVal = eval("objForm." + iLoop + ".value"); else if (aMandatory[iLoop][1] == "Radio") { var oEle = eval("objForm." + iLoop); var iLen = oEle.length; for (var iEle = 0; iEle < iLen; iEle++) if (oEle[iEle].checked) { strVal = oEle[iEle].value; break; } } else if (aMandatory[iLoop][1] == "Select") { var iIdx = eval("objForm." + iLoop + ".selectedIndex"); if (iIdx > -1) strVal = eval("objForm." + iLoop + "[" + iIdx + "].value"); else strVal = ""; } strVal = alltrim(strVal); if (strVal == "") { alert('Please enter a value for ' + aMandatory[iLoop][0] + '.'); if (aMandatory[iLoop][2] != "") eval("objForm." + aMandatory[iLoop][2] + ".focus()"); else { if (aMandatory[iLoop][1] == "Radio") eval("objForm." + iLoop + "[0].focus()"); else eval("objForm." + iLoop + ".focus()"); } return false; } } return true; } function disableButtons(objForm) { var i for(i=0; i< max; i++ ) { if( aForm.elements[i].type != "hidden" && aForm.elements[i].type != "button" && !aForm.elements[i].disabled && !aForm.elements[i].readOnly ) { aForm.elements[i].focus(); break; } } } } }
rss
Карта