Javascript trouble

monoVertex

I'm back!
Reaction score
460
Ok, here I am with another chunk of redudant script :D.

This is the javascript part.
Code:
<script type="text/javascript">
Image1a = new Image(70,34)
Image1a.src = "interface/ba_home.gif"
Image2a = new Image(70,34)
Image2a.src = "interface/ba_moisil.gif"
Image3a = new Image(70,34)
Image3a.src = "interface/ba_liceul.gif"
Image4a = new Image(70,34)
Image4a.src = "interface/ba_merite.gif"
Image5a = new Image(70,34)
Image5a.src = "interface/ba_forum.gif"
Image6a = new Image(70,34)
Image6a.src = "interface/ba_galerie.gif"

function home(){
document.home.src = Image1a.src; return true;
}
function moisil(){
document.moisil.src = Image2a.src; return true;
}
function liceul(){
document.liceul.src = Image3a.src; return true;
}
function merite(){
document.merite.src = Image4a.src; return true;
}
function forum(){
document.forum.src = Image5a.src; return true;
}
function galerie(){
document.galerie.src = Image6a.src; return true;
}

function homeo(){
document.home.src = "interface/b_home.gif";
}
function moisilo(){
document.moisil.src = "interface/b_moisil.gif";
}
function liceulo(){
document.liceul.src = "interface/b_liceul.gif";
}
function meriteo(){
document.merite.src = "interface/b_merite.gif";
}
function forumo(){
document.forum.src = "interface/b_forum.gif";
}
function galerieo(){
document.galerie.src = "interface/b_galerie.gif";
}
</script>

And this is the html part that use that stuff above.
Code:
<img src="interface/b_home.gif" border="0" width="70" height="34" name="home" onmouseOver="home()" onmouseOut="homeo()"/>
<img src="interface/b_moisil.gif" border="0" width="70" height="34" name="moisil" onmouseOver="moisil()" onmouseOut="moisilo()"/>
<img src="interface/b_liceul.gif" border="0" width="70" height="34" name="liceul" onmouseOver="liceul()" onmouseOut="liceulo()"/>
<img src="interface/b_merite.gif" border="0" width="70" height="34" name="merite" onmouseOver="merite()" onmouseOut="meriteo()"/>
<img src="interface/b_forum.gif" border="0" width="70" height="34" name="forum" onmouseOver="forum()" onmouseOut="forumo()"/>
<img src="interface/b_galerie.gif" border="0" width="70" height="34" name="galerie" onmouseOver="galerie()" onmouseOut="galerieo()"/>

I get errors on page and the buttons don't change... Please help me. Thanks in advance :).



EDIT: Problem solved. It seems that the browser was confused between functions like "moisil()" and "moisilo()". I replaced with "moisilOver()" and "moisilOut()" and it worked perfectly. However, if anyone knows the reason for this, please post, it might help me in the future :).
 

DDRtists

ɹoʇɐɹǝpoɯ ɹǝdns
Reaction score
415
Not really a fix, but why don't you use arrays? It would make the script much cleaner.
 

mase

____ ___ ____ __
Reaction score
154
HTML:
<script type="text/javascript">
var images = new Array()
var realimgs = new Array()
images[1] = "interface/ba_home.gif"
images[2] = "interface/ba_moisil.gif"
images[3] = "interface/ba_liceul.gif"
images[4] = "interface/ba_merite.gif"
images[5] = "interface/ba_forum.gif"
images[6] = "interface/ba_galerie.gif"
realimgs[1] = "interface/b_home.gif";
realimgs[2] = "interface/b_moisil.gif";
realimgs[3] = "interface/b_liceul.gif";
realimgs[4] = "interface/b_merite.gif";
realimgs[5] = "interface/b_forum.gif"
realimgs[6] = "interface/b_galerie.gif"

var elem = new Object
function showIMG(img, target){
elem = getElementById(target)
document.elem.src = images[img]
}
function hideIMG(img, target){
elem = getElementById(target)
document.elem.src = realimgs[img]
}

_______

<img src="interface/b_home.gif" border="0" width="70" height="34" id="home" onmouseOver="showIMG(1, 'home')" onmouseOut="hideIMG(1, 'home')"/>
</script>
And so on :)
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top