Why not consider a different approach? Do you really have to store an array or list of IDs within your script? This solution should function well on IE7, although I am unable to test it myself.
Here is a suggested HTML structure:
<div id="container">
<div id="div_rssims_prefix">Prefix
<input id="f1" type="text" value="Prefix"></input>
</div>
<div id="div_rssims_firstname">First Name
<input id="f2" type="text" value="First Name"></input>
</div>
<div id="div_rssims_middlename">Middle Name
<input id="f3" type="text" value="Middle Name"></input>
</div>
</div>
And the corresponding Javascript code:
var container = document.getElementById("container"),
length1 = container.childNodes.length,
i = 0,
node1,
length2,
node2,
j;
while (i < length1) {
node1 = container.childNodes[i];
if (node1 && node1.nodeType === 1 && /^div_rssims_\S+$/.test(node1.id)) {
length2 = node1.childNodes.length;
j = 0;
while (j < length1) {
node2 = node1.childNodes[j];
if (node2 && node2.nodeType === 1 && /^f\d+$/.test(node2.id)) {
node2.onfocus = function () {
this.style.border = 'solid 1px #0033CC';
this.parentNode.style.color = '#0033CC'
}
node2.onblur = function () {
this.style.border = 'solid 1px #ABADB3';
this.parentNode.style.color = ''
}
}
j += 1;
}
}
i += 1;
}
You can also view it on jsfiddle.
Alternatively, here's a more generic approach based on guessed HTML:
Javascript
function getElementsById(node, regex) {
var nodeList = arguments[2] || [];
if (node.nodeType === 1) {
if (regex.test(node.id)) {
nodeList.push(node);
}
node = node.firstChild;
while (node) {
getElementsById(node, regex, nodeList);
node = node.nextSibling;
}
}
return nodeList;
}
var inputs = getElementsById(document.getElementById("container"), /^f\d+$/),
length = inputs.length,
i = 0,
node;
while (i < length) {
node = inputs[i];
node.onfocus = function () {
this.style.border = 'solid 1px #0033CC';
this.parentNode.style.color = '#0033CC'
}
node.onblur = function () {
this.style.border = 'solid 1px #ABADB3';
this.parentNode.style.color = ''
}
i += 1;
}
You can find this version on jsfiddle.
If you have control over your markup, consider a layout like this instead:
CSS
label {
float: left;
margin-right: 5px;
}
input {
display: block;
}
HTML
<div id="container">
<label for="f1">Prefix</label>
<input id="f1" type="text" value="Enter value"></input>
<label for="f2">First Name</label>
<input id="f2" type="text" value="Enter value"></input>
<label for="f3">Middle Name</label>
<input id="f3" type="text" value="Enter value"></input>
</div>
Corresponding Javascript:
function getElementsById(node, regex) {
var nodeList = arguments[2] || [];
if (node.nodeType === 1) {
if (regex.test(node.id)) {
nodeList.push(node);
}
node = node.firstChild;
while (node) {
getElementsById(node, regex, nodeList);
node = node.nextSibling;
}
}
return nodeList;
}
function getPreviousSibling(element) {
var p = element;
do {
p = p.previousSibling;
} while (p && p.nodeType !== 1);
return p;
}
var inputs = getElementsById(document.getElementById("container"), /^f\d+$/),
length = inputs.length,
i = 0,
node;
while (i < length) {
node = inputs[i];
node.onfocus = function () {
if (this.value === "Enter value") {
this.value = "";
}
this.style.border = 'solid 1px #0033CC';
getPreviousSibling(this).style.color = '#0033CC'
}
node.onblur = function () {
if (this.value === "") {
this.value = "Enter value";
}
this.style.border = 'solid 1px #ABADB3';
getPreviousSibling(this).style.color = ''
}
i += 1;
}
You can check out this version on jsfiddle.