Javascript - Dynamically generate span IDs after styling radio buttons
<p>I have a problem. I'm trying to do a show/hide on the "activationframe" and "equipmentframe" divs based on a radio button selection. I had it working fine but then the client decided to add styled radio buttons to the equation. That has broken my show/hide toggle. How do I incorporate that into the styled radio button JS?</p>

<p>Here is the styled radio buttons script:</p>

<pre><code>var checkboxHeight = "25";
var radioHeight = "25";
var selectWidth = "190";

document.write('&lt;style type="text/css"&gt;input.styled { display: none; } select.styled { position: relative; width: ' + selectWidth + 'px; opacity: 0; filter: alpha(opacity=0); z-index: 5; } .disabled { opacity: 0.5; filter: alpha(opacity=50); }&lt;/style&gt;');

var Custom = {
init: function() {
    var inputs = document.getElementsByTagName("input"), span = Array(), textnode, option, active;
    for(a = 0; a &lt; inputs.length; a++) {
        if((inputs[a].type == "radio") &amp;&amp; inputs[a].className == "styled") {
            span[a] = document.createElement("span");
            span[a].className = inputs[a].type;

            if(inputs[a].checked == true) {
                    position = "0 -" + (radioHeight*2) + "px";
                    span[a].style.backgroundPosition = position;
                }
            inputs[a].parentNode.insertBefore(span[a], inputs[a]);
            inputs[a].onchange = Custom.clear;
            if(!inputs[a].getAttribute("disabled")) {
                span[a].onmousedown = Custom.pushed;
                span[a].onmouseup = Custom.check;
            } else {
                span[a].className = span[a].className += " disabled";
            }
        }
    }
    inputs = document.getElementsByTagName("select");
    for(a = 0; a &lt; inputs.length; a++) {
        if(inputs[a].className == "styled") {
            option = inputs[a].getElementsByTagName("option");
            active = option[0].childNodes[0].nodeValue;
            textnode = document.createTextNode(active);
            for(b = 0; b &lt; option.length; b++) {
                if(option[b].selected == true) {
                    textnode = document.createTextNode(option[b].childNodes[0].nodeValue);
                }
            }
            span[a] = document.createElement("span");
            span[a].className = "select";
            span[a].id = "select" + inputs[a].name;
            span[a].appendChild(textnode);
            inputs[a].parentNode.insertBefore(span[a], inputs[a]);
            if(!inputs[a].getAttribute("disabled")) {
                inputs[a].onchange = Custom.choose;
            } else {
                inputs[a].previousSibling.className = inputs[a].previousSibling.className += " disabled";
            }
        }
    }
    document.onmouseup = Custom.clear;
},
pushed: function() {
    element = this.nextSibling;
    if(element.checked == true &amp;&amp; element.type == "radio") {
        this.style.backgroundPosition = "0 -" + radioHeight*3 + "px";
    } else {
        this.style.backgroundPosition = "0 -" + radioHeight + "px";
    }
},
check: function() {
    element = this.nextSibling;
            this.style.backgroundPosition = "0 -" + radioHeight*2 + "px";
            group = this.nextSibling.name;
            inputs = document.getElementsByTagName("input");
            for(a = 0; a &lt; inputs.length; a++) {
                if(inputs[a].name == group &amp;&amp; inputs[a] != this.nextSibling) {
                    inputs[a].previousSibling.style.backgroundPosition = "0 0";
        }
        element.checked = true;
    }
},
clear: function() {
    inputs = document.getElementsByTagName("input");
    for(var b = 0; b &lt; inputs.length; b++) {
        if(inputs[b].type == "radio" &amp;&amp; inputs[b].checked == true &amp;&amp; inputs[b].className == "styled") {
            inputs[b].previousSibling.style.backgroundPosition = "0 -" + radioHeight*2 + "px";
        } else if(inputs[b].type == "radio" &amp;&amp; inputs[b].className == "styled") {
            inputs[b].previousSibling.style.backgroundPosition = "0 0";
        }
    }
},
choose: function() {
    option = this.getElementsByTagName("option");
    for(d = 0; d &lt; option.length; d++) {
        if(option[d].selected == true) {
            document.getElementById("select" + this.name).childNodes[0].nodeValue = option[d].childNodes[0].nodeValue;
        }
    }
}
}
window.onload = Custom.init;
</code></pre>

<p>Here is my old script that does the show/hide:</p>

<pre><code>function showhideInstall(installtype) {
if (installtype == "equipmentswap") {
    document.getElementById("activationframe").style.display = 'none';
    document.getElementById("equipmentframe").style.display = 'block';
} else {
    document.getElementById("activationframe").style.display = 'block';
    document.getElementById("equipmentframe").style.display = 'none';
}
}
</code></pre>

<p>And finally, my HTML:</p>

<pre><code>&lt;div id="activationtoggle"&gt;
            &lt;form class="radiobuttons"&gt;
                &lt;input type="radio" name="installtype" value="activation" class="styled" onclick="showhideInstall(this.value);" checked&gt;&amp;nbsp;&amp;nbsp;New Activation
                &lt;input type="radio" name="installtype" value="equipmentswap" class="styled" onclick="showhideInstall(this.value);" &gt;&amp;nbsp;&amp;nbsp;Equipment Swap
            &lt;/form&gt;
        &lt;/div&gt;

        &lt;div id="activationframe"&gt;
            &lt;div id="activationchecklist"&gt;
                    code here
                 &lt;/div&gt;

             &lt;div id="equipmentframe"&gt;
                &lt;div id="equipmentswap"&gt;
                &lt;h2&gt;Equipment Swap&lt;/h2&gt;
               more code here
                 &lt;/div&gt;
</code></pre>

<p>Any help would be GREATLY appreciated. I'm middling at JS (at best) and this has proven to be a giant time sink.</p>
