window.onload = initialise; function initialise() { var objForms = document.getElementsByTagName('form'); // Attach an event handler for each form for (var iCounter=0; iCounter 0) { // If not valid, display error messages var objError = objForm.getElementsByTagName('div'); // Look for existing errors for (var iCounter=0; iCounter 0) objAnchor.id = strErrorID; // Use the label prompt for the error message objAnchor.appendChild(document.createTextNode(strError)); // Add keyboard and mouse events to set focus to the form control objAnchor.onclick = function(event){return focusFormField(this, event);} objAnchor.onkeypress = function(event){return focusFormField(this, event);} objListItem.appendChild(objAnchor); objList.appendChild(objListItem); } function focusFormField(objAnchor, objEvent) { // Allow keyboard navigation over links if (objEvent && objEvent.type == 'keypress') if (objEvent.keyCode != 13 && objEvent.keyCode != 32) return true; // set focus to the form control var strFormField = objAnchor.href.match(/[^#]\w*$/); var objForm = getForm(strFormField); objForm[strFormField].focus(); return false; } // Function to return the form element from a given form field name function getForm(strField) { var objElement = document.getElementById(strField); // Find the appropriate form do { objElement = objElement.parentNode; } while (!objElement.tagName.match(/form/i) && objElement.parentNode); return objElement; } // Function to log the error in a list function logError(objField, objLabel, objList, strErrorID) { // Search the label for the error prompt for (var iCounter=0; iCounter