I am trying to dynamically alter the state of a select element (with a default height of 6 options) and swap it with 6 span elements.
Disabling the select is not an option.
Once all of the span elements are created- my idea is just use the replaceChild function and swap the select element with the newSpan(s).
However it is not working.
Please lend me some insight as to how I can resolve this issue. Any help is greatly appreciated.
Thanks in advance,
Mike.
[blue]Go to work to learn. Don't go to work to earn.[/blue]
Disabling the select is not an option.
Code:
// Create variables for the select box element and get the height of the select box
var scorecardSelector = document.thisForm.scorecard_selected;
var numSpans = parseInt(document.thisForm.scorecard_selected.size);
var stack = [];
// Push each select box's text (up to the max visible) into a one-dimensional array
for (optionCounter = 0; optionCounter < numSpans; optionCounter ++){
// ... if the height is greater than the number of options
try{
stack.push(scorecardSelector[optionCounter].text);
}catch (err){
stack.push("");
}
}
// Put select box's text values in order
stack.reverse();
// Pop out each item in the array and create span elements for them
while (stack.length > 0){
var current = stack.pop();
var newSpan = document.createElement("span");
// some css ...
newSpan.setAttribute("id", "n10");
var scorecardName = document.createTextNode(current.valueOf());
newSpan.appendChild(scorecardName);
var parentSpan = current.parentNode;
parentSpan.replaceChild(newSpan, current);
}
}
Once all of the span elements are created- my idea is just use the replaceChild function and swap the select element with the newSpan(s).
However it is not working.
Please lend me some insight as to how I can resolve this issue. Any help is greatly appreciated.
Thanks in advance,
Mike.
[blue]Go to work to learn. Don't go to work to earn.[/blue]