Changing style sheets not working in IE
<p>I've got a style sheet changer with javascript but it doesn't work in IE while working good in Firefox and Chrome. The HTML code I'm using is this:</p>

<pre><code>&lt;head&gt;

&lt;link href="defualt.css" rel="stylesheet" type="text/css" /&gt;
&lt;link href="theme1.css" title="theme1" rel="alternate stylesheet" type="text/css" /&gt;
&lt;link href="theme2.css" title="theme2" rel="alternate stylesheet" type="text/css" /&gt;
&lt;link href="theme3.css" title="theme3" rel="alternate stylesheet" type="text/css"  /&gt;

&lt;script type="text/javascript" src="javascript.js"&gt;&lt;/script&gt;

&lt;/head&gt;
&lt;body&gt;

&lt;form&gt;
    &lt;select id="myList" &gt;
        &lt;option value="default"&gt;Default&lt;/option&gt;
        &lt;option value="theme1"&gt;Theme 1&lt;/option&gt;
        &lt;option value="theme2"&gt;Theme 2&lt;/option&gt;  
        &lt;option value="theme3"&gt;Theme 3&lt;/option&gt;
    &lt;/select&gt;
&lt;/form&gt;

&lt;/body&gt;
</code></pre>

<p>And the javascript:</p>

<pre><code>function setActiveStyleSheet(title) {
    var i, a, main;
    for (i = 0; (a = document.getElementsByTagName("link")[i]) ; i++) {
        if (a.getAttribute("rel").indexOf("style") != -1 &amp;&amp; a.getAttribute("title")) {
            a.disabled = true;
            if (a.getAttribute("title") == title) a.disabled = false;
        }
    }
    createCookie("style", title, 7);
}

function getActiveStyleSheet() {
    var i, a;
    for (i = 0; (a = document.getElementsByTagName("link")[i]) ; i++) {
        if (a.getAttribute("rel").indexOf("style") != -1 &amp;&amp; a.getAttribute("title") &amp;&amp; !a.disabled) return a.getAttribute("title");
    }
}

function getPreferredStyleSheet() {
    var i, a;
    for (i = 0; (a = document.getElementsByTagName("link")[i]) ; i++) {
        if (a.getAttribute("rel").indexOf("style") != -1
           &amp;&amp; a.getAttribute("rel").indexOf("alt") == -1
           &amp;&amp; a.getAttribute("title")
           ) return a.getAttribute("title");
    }
}

function getTheme() {
    var storedThemeVal = readCookie('selectedTheme');
    if (storedThemeVal != null &amp;&amp; storedThemeVal != "") {
        for (var i = 0; i &lt; selectBox.options.length; i++) {
            if (selectBox.options[i].value == storedThemeVal) {
                selectBox.selectedIndex = i;
            }
        }
    }
}

function setTheme() {
    var selectedThemeVal = selectBox.options[selectBox.selectedIndex].value;
    createCookie('selectedTheme', selectedThemeVal);
}

function createCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i &lt; ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}



function initiate()
{

    window.selectBox = document.getElementById("myList");
    var cookie = readCookie("style");
    var title = cookie ? cookie : getPreferredStyleSheet();
    setActiveStyleSheet(title);
    getTheme();
    selectBox.onchange = function () {
        setActiveStyleSheet(this.value);
        setTheme();
    };





}

window.onload = initiate;
</code></pre>

<p>I can't understand why this won't work in IE since it's working so good in the other browsers. And I prefer to keep all my javascript in my separate document javascript.js as well as I don't want to work with a library.</p>
