diff options
| author | Nathan Kinkade <nath@nkinka.de> | 2008-02-03 23:23:24 +0000 |
|---|---|---|
| committer | Nathan Kinkade <nath@nkinka.de> | 2008-02-03 23:23:24 +0000 |
| commit | d895b852a6e160496ffc760d46d3719a3d62ff86 (patch) | |
| tree | 52230bb04148197e8312e09b5c5273417e7a3be9 /js/common.js | |
Initial checkin of nutridb.org and basic subversion directory structure
Diffstat (limited to 'js/common.js')
| -rw-r--r-- | js/common.js | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/js/common.js b/js/common.js new file mode 100644 index 0000000..de2dde2 --- /dev/null +++ b/js/common.js @@ -0,0 +1,55 @@ +function validateNotEmpty(fields) { + + var myFields = new Array(); + myFields = fields.split(","); + + for ( idx = 0; idx < myFields.length; idx++ ) { + var myField = getElement(myFields[idx]); + /* + change the bgcolor back to white just in case the this field + was already colored and the user has since filled it in. + */ + myField.style.backgroundColor = "#ffffff"; + if ( empty(myField.value) ) { + alert("Please fill in required field - highlighted in red."); + myField.style.backgroundColor = "#efb5b5"; + myField.focus(); + return false; + } + } + +} + +function empty(field) { + + field = trim(field); + if ( field ) { + return false; + } else { + return true; + } + +} + +function trim(string) { + string = string.replace(/^\s+/, ''); + string = string.replace(/\s+$/, ''); + return string; +} + +function getElement(elemid) { + + /* the former for Firefox and crew, the latter for IE */ + return (document.getElementById) ? document.getElementById(elemid) : document.all[elemid]; + +} + +function submitForm(formid) { + + var myForm = getElement(formid); + + myForm.submit(); + + return true; + +} |
