markwaldin
Technical User
If I try an address a object property using a variable it does not work. For example having document.myimage.src having myimage as an image objects name is identified correctly. Substituting a variable for myimage such as newimage=myimage; document.newimage.src is not recognized as a defined object. Below is a piece of sample code showing what I am trying to do that doesn't work:
/*
this script creates a navigational bar with "no_of_tabs" tabs on it. If a user clicks on a tab, all other tabs turn tabblue.gif and the active tab goes tabwhite.gif
*/
<script language="javascript">
topnav_builder(10,0)
//initialize the top nav bar
function topnav_builder(no_of_tabs,activetab) {
document.write("<img src=\"logo.gif\" >"
tab_title=new Array()
tab_title[0]="Individual"
tab_title[1]="Retailers"
tab_title[2]="Pro Photographers"
tab= new Array ("tab0","tab1","tab2","tab3","tab4","tab5","tab6","tab7","tab8","tab9"
for (i=0;i<no_of_tabs;++i) {
if(i==activetab) {
document.writeln("<DIV STYLE= \"left:"+(200+200*i)+"px;top:50px;\">" )
//in the next line the image tab is created
document.writeln("<img src=\"tabwhite.gif \" name=\""+tab+"\" >"
document.writeln("</DIV>"
document.writeln("<DIV STYLE= \"left:"+(200+200*i)+"; top:53px;\">" )
document.writeln("<a href=\"javascript:tabcontroller("+i+","+activetab+"\">"+tab_title+"</a>"
document.writeln("</DIV>"
} else {
document.writeln("<DIV STYLE= \"left:"+(200+200*i)+"px; top:50px\">" )
document.writeln("<img src=\"tabblue.gif\" name=\""+tab+"\" >"
document.writeln("</DIV>"
document.writeln("<DIV STYLE= \"left:"+(200+200*i)+"; top:53px;\">" )
document.writeln("<a href=\"javascript:tabcontroller("+i+","+activetab+"\">"+tab_title+"</a>"
document.writeln("</DIV>"
}
}
}
function tabcontroller(tabselect,no_of_tabs) {
//here the active_tab which is white is turned blue but it doesn't work. If I change tab[active_tab] to it's value then it works...??
document.tab[active_tab].src=tabblue.jpg'
//then the selected tab is turned white
document.tab[tabselect].src='sidetab_white.jpg'
//then the selected tab is made "active"
active_tab=tabselect
}
</script>
/*
this script creates a navigational bar with "no_of_tabs" tabs on it. If a user clicks on a tab, all other tabs turn tabblue.gif and the active tab goes tabwhite.gif
*/
<script language="javascript">
topnav_builder(10,0)
//initialize the top nav bar
function topnav_builder(no_of_tabs,activetab) {
document.write("<img src=\"logo.gif\" >"
tab_title=new Array()
tab_title[0]="Individual"
tab_title[1]="Retailers"
tab_title[2]="Pro Photographers"
tab= new Array ("tab0","tab1","tab2","tab3","tab4","tab5","tab6","tab7","tab8","tab9"
for (i=0;i<no_of_tabs;++i) {
if(i==activetab) {
document.writeln("<DIV STYLE= \"left:"+(200+200*i)+"px;top:50px;\">" )
//in the next line the image tab is created
document.writeln("<img src=\"tabwhite.gif \" name=\""+tab+"\" >"
document.writeln("</DIV>"
document.writeln("<DIV STYLE= \"left:"+(200+200*i)+"; top:53px;\">" )
document.writeln("<a href=\"javascript:tabcontroller("+i+","+activetab+"\">"+tab_title+"</a>"
document.writeln("</DIV>"
} else {
document.writeln("<DIV STYLE= \"left:"+(200+200*i)+"px; top:50px\">" )
document.writeln("<img src=\"tabblue.gif\" name=\""+tab+"\" >"
document.writeln("</DIV>"
document.writeln("<DIV STYLE= \"left:"+(200+200*i)+"; top:53px;\">" )
document.writeln("<a href=\"javascript:tabcontroller("+i+","+activetab+"\">"+tab_title+"</a>"
document.writeln("</DIV>"
}
}
}
function tabcontroller(tabselect,no_of_tabs) {
//here the active_tab which is white is turned blue but it doesn't work. If I change tab[active_tab] to it's value then it works...??
document.tab[active_tab].src=tabblue.jpg'
//then the selected tab is turned white
document.tab[tabselect].src='sidetab_white.jpg'
//then the selected tab is made "active"
active_tab=tabselect
}
</script>