I have the following page:
<html>
<head>
<title>Test</title>
<script type="text/javascript">
function BuildTree() {
var total = 0;
var pages = document.getElementsByTagName('custom:page');
var questions = pages[0].getElementsByTagName('custom:question');
for (var i = 0; i < questions.length; ++i) {
var question = questions[i];
var val = question.getAttribute('value')
total += val;
}
alert("Total: " + total);
};
</script>
</head>
<body>
<custom:pages>
<custom:page>
<custom:question value="1">aaa</custom:question>
<custom:question value="2">bbb</custom:question>
<custom:question value="3">ccc</custom:question>
</custom:page>
<custom:page>
<custom:question value="1">aaa</custom:question>
<custom:question value="2">bbb</custom:question>
<custom:question value="3">ccc</custom:question>
</custom:page>
</custom:pages>
<input id="btnTest" type="button" value="Test" onclick="BuildTree();" />
</body>
</html>
When I click the Test button in IE the result is 0, when I click it in FF the result is 0123.
How can I get the same result in both browsers? i.e. ‘0123’.
Note that I’ve trimmed this down to as simple an example as possible. I cannot use jquery or any third party libraries, I need a pure Javasscript solution. I also cannot change the custom: tags.
Thanks
1 Answer