0

Below is my code. It is supposed to filter a table. It functions great in everything but IE. Can you help?

Perhaps there is a missing tag or something. I've been over it a number of times and could really do with someone's help please!

<script type="text/javascript">
function hasPath(element, cls) {
    return (' ' + element.getAttribute('pathway')).indexOf(cls) > -1;
}

function hasLevel(element, cls) {
    return (' ' + element.getAttribute('level')).indexOf(cls) > -1;
}

function hasBody(element, cls) {
    return (' ' + element.getAttribute('body')).indexOf(cls) > -1;
}

function QualificationSearch() {
    var imgdiv = document.getElementById("Chosen_Pathway_img");
    var p = document.getElementById("PathwaySelect");
    var pathway = p.options[p.selectedIndex].value;
    if (pathway == "ALLPATHS") {
        pathway = "";
        imgdiv.src = "/templates/superb/images/QualChecker/pic_0.png"
    }
    if (pathway == "ES") {
        imgdiv.src = "/templates/superb/images/QualChecker/pic_1.png"
    }
    if (pathway == "HOUSING") {
        imgdiv.src = "/templates/superb/images/QualChecker/pic_2.png"
    }
    if (pathway == "PLAYWORK") {
        imgdiv.src = "/templates/superb/images/QualChecker/pic_3.png"
    }
    if (pathway == "SC") {
        imgdiv.src = "/templates/superb/images/QualChecker/pic_4.png"
    }
    if (pathway == "YW") {
        imgdiv.src = "/templates/superb/images/QualChecker/pic_5.png"
    }
    var a = document.getElementById("AwardingBodySelect");
    var awardingBody = a.options[a.selectedIndex].value;
    if (awardingBody == "ALLBODIES") {
        awardingBody = "";
    }
    var levelGroup = document.getElementsByName("LevelGroup");
    var chosenLevel = ""
    for (var g = 0; g < levelGroup.length; g++) {
        if (levelGroup[g].checked) {
            chosenLevel += levelGroup[g].value + " ";
        }
    }
    if (chosenLevel == undefined) {
        var chosenLevel = "";
    } else {
        var splitLevel = chosenLevel.split(" ");
        var levelA = splitLevel[0];
        var levelB = splitLevel[1];
        var levelC = splitLevel[2];
        var levelD = splitLevel[3];
        if (levelA == "") {
            levelA = "NOLVL"
        }
        if (levelB == "") {
            levelB = "NOLVL"
        }
        if (levelC == "") {
            levelC = "NOLVL"
        }
        if (levelD == "") {
            levelD = "NOLVL"
        }
    }
    var fil = document.getElementsByName("QList");
    for (var i = 0; i < fil.length; i++) {
        fil.item(i).style.display = "none";
        if ((hasBody(fil.item(i), awardingBody) == true || awardingBody == "") && (hasPath(fil.item(i), pathway) == true || pathway == "") && ((hasLevel(fil.item(i), levelA) == true || hasLevel(fil.item(i), levelB) == true || hasLevel(fil.item(i), levelC) == true || hasLevel(fil.item(i), levelD) == true) || chosenLevel == "")) {
            fil.item(i).style.display = "block";
        }
    }
}
</script>
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • What happens in IE? Is there an error? Does it work, but not correctly? – Matt Apr 20 '12 at 16:40
  • 3
    @Giles Check your console in IE. Press F12 to find it. This is a lot of code for us to parse through, and "it doesn't work" provides little direction. – Sampson Apr 20 '12 at 16:41
  • Could it be the non-standard attributes ("pathway," "level," and "body)? If not, I have no idea. What version of IE does it not work in? – Dagg Nabbit Apr 20 '12 at 16:50
  • No syntax errors in IE7 mode. What does it do wrong in IE? – Snuffleupagus Apr 20 '12 at 16:52
  • Basically it isnt running the full script in IE. You can view it on http://career-path-tool.co.uk/index.php/2011-08-09-14-49-39 – Giles Wilkinson Apr 21 '12 at 16:23

1 Answers1

0

Check your semicolons. IE is far more strict on that kind of stuff than FF.

C.S.
  • 422
  • 2
  • 9
  • I thought IE had the same rules for ASI as Moz? – Dagg Nabbit Apr 20 '12 at 17:03
  • I am not familiar with the ASI acronym GGG. Also, your comment about the non-standard attributes is also probably an issue. I know there are shims out there for non-standard attributes in IE, but I cannot assume Giles is using them. – C.S. Apr 20 '12 at 17:10
  • Ah, ASI... http://stackoverflow.com/questions/2846283/what-are-the-rules-for-javascripts-automatic-semicolon-insertion – C.S. Apr 20 '12 at 17:13
  • I just assumed non-standard attributes must fail in "some browsers," or we wouldn't need `data-` ... but as far as I know ASI is the same in IE. It does treat commas in a non-standard way in array and object literals, though. – Dagg Nabbit Apr 20 '12 at 17:22
  • Custom attributes haven't caused any troubles in IE, AFAIK and by my own experience. – Teemu Apr 20 '12 at 17:25
  • 1
    Well I learned something today. Even though ASI is essentially an error correction mechanism, the performance difference is < 1% on my generic test. http://jsperf.com/asi-performance/2 As for non-standard attributes, I last ran into it when working with tinyMCE back in 2009. So that said, perhaps my answer is both irrelevant and incorrect in different ways. But just for my own sanity, please use semicolons where they are expected. – C.S. Apr 20 '12 at 17:47