Improvements to form script

13 November 2005

I have made various improvements to the way the form enhancement script works. On the advice of Mark Wubbenthe event handlers are now set with proper event model methods and not with the setAttribute property. I kind of see your point, Mark. More importantly, the script is now much more generic and should work on just about any page you plug it in to. It now works by getting the id of the input element that is currently in focus and searching for a label element with a matching for attribute. This means we are not relying on any other feature of the markup to make the script work. id = this.getAttribute('id'); label = document.getElementsByTagName('label'); for (k = 0 ; k < label.length ; k++) { if (label[k].getAttribute('for') == id) { label[k].style.color = '#a00'; } One issue I'm having is being able to concatenate two HTML Object collections. I have an array of inputs and an array of textareas, so my question is, why can I not concatenate them as follows. input = document.getElementsByTagName('input'); textarea = document.getElementsByTagName('textarea'); both = input.concat(text); At the moment I am using the DOM Level 0 method of getting form elements; which works, but I'd rather do it the previous way, and build my own arrays. Any ideas?