As usual, develop something in FF and as soon as you get near IE everything decides to pack up and go home.
I'm getting an object expected error, forgive me if it's simple, I'm new to JavaScript.
HTML Code
<div id="tabsCon" class="tabsContainer">
<span id="tab1" class="activeTab" onclick="javascript:changeTab('tab1');">Tab 1</span>
<span id="tab2" class="inactiveTab" onclick="javascript:changeTab('tab2');">Tab 2</span>
<span id="tab3" class="inactiveTab" onclick="javascript:changeTab('tab3');">Tab 3</span>
<span id="tab4" class="inactiveTab" onclick="javascript:changeTab('tab4');">Tab 4</span>
<span id="tab5" class="inactiveTab" onclick="javascript:changeTab('tab5');">Tab 5</span>
<span id="tab6" class="inactiveTab" onclick="javascript:changeTab('tab6');">Tab 6</span>
</div>
JavaScript
function changeTab(tab){
tabCont = document.getElementById('tabsCon');
items = tabCont.getElementsByTagName('span');
var len = items.length;
for (i=1;i<=len;i++){
if (document.getElementById('tab'+i).getAttribute('class') == "activeTab" || document.getElementById('tab'+i).getAttribute('className' == "activeTab")
document.getElementById('tab'+i).setAttribute("class", "inactiveTab");
document.getElementById('tab'+i).setAttribute("className", "inactiveTab");
}
obj2 = document.getElementById(tab);
obj2.setAttribute("class", "activeTab");
obj2.setAttribute("className", "activeTab");
http.open('get', page+'?task=changeTab&tab='+tab);
http.onreadystatechange = handleResponse;
http.send(null);
}
There is obviously more to the .js file but I've included what matters.
As I say, it's all working in firefox, any help would be greatly appreciated.
You are kidding, right?!
No matter what broswer you test this on, will not work at all.
Although invisible to novice attention. What 'explorer'?! It contains errors, javascript errors, therefore your statement is false. It shall faill in fx and any other browser.
But this code should not:
function changeTab(tab){
var tabCont = document.getElementById('tabsCon');
var items = tabCont.getElementsByTagName('span');
var len = items.length;
for (i=1;i<=len;i++){
if (document.getElementById('tab'+i).getAttribute('class') == "activeTab" || document.getElementById('tab'+i).getAttribute('className' == "activeTab")){
document.getElementById('tab'+i).setAttribute("class", "inactiveTab");
document.getElementById('tab'+i).setAttribute("className", "inactiveTab") }
}
var obj2 = document.getElementById(tab);
obj2.setAttribute("class", "activeTab");
obj2.setAttribute("className", "activeTab");
/* http.open('get', page+'?task=changeTab&tab='+tab);
http.onreadystatechange = handleResponse;
http.send(null);
*/ }
[! I've isolated last lines of code because its externaly dependant]
Colored parts are all errors; from red hot to a warning green.
Your main loop conditional evaluator is not closed, so the addressed object fails to get picked. So here we are, the error report is correct!
You are also violating global space with undeclared variable names causing mixed scope reference. Your declared "len" variable is not sharing the same space with two previously undeclared 'vars' which in fact, will not be treated as vars but properties of the top host scripting object.
The last but not the least is missing {} after the loop conditional. It is legal, but not safe.
p.s.:
- who wrote this code?
OK
That would be all.
Regards and happy coding.