javascript help

Discuss all aspects of programming here.

Moderator: The Mod Squad

javascript help

Postby Toby B. » Mon Aug 16, 2004 9:52 pm

Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>

<TITLE>Untitled</TITLE>
<link rel="STYLESHEET" type="text/css" href="./../../common/cstechstyle.css">
</head>

<body bgcolor="#999999" text="white" link="white" vlink="white" alink="white">

<SCRIPT language="javascript1.1">

   infoOn = new Image()
   infoOn.src = "./../../images/getinfodown.gif"

   infoOff = new Image()
   infoOff.src = "./../../images/getinfoup.gif"

function changeImg(cImg,ref) {
document.images[cImg].src = ref.src
}
</SCRIPT><table width="100%" border="0">




<tr>
<td align="left" valign="top" class="submenuheading"><a href="sidenav.html"><font color="yellow">Back</font></a></td></tr>

       <tr><td height="50"></td></tr>

   <tr><td align="center" valign="top" class="submenuheading">Quickspecs</td></tr>

   
         <tr>
<td align="center" valign="top">
<a href="5bw1xx/5bw112/5BW112quickspecs.html" target="content"
onMouseOver="changeImg('info',infoOn)"
onMouseOut="changeImg('info',infoOff)">
<img name=info src="./../../images/getinfoup.gif" border=0></a></td> </tr><BR>

<tr><td height="50"></td></tr>

   <tr><td align="center" valign="top" class="submenuheading">Heading 2</td></tr>


         <tr>
<td align="center" valign="top">
<a href="5bw1xx/5bw112/5BW112quickspecs.html" target="content"
onMouseOver="changeImg('info',infoOn)"
onMouseOut="changeImg('info',infoOff)">
<img name=info src="./../../images/getinfoup.gif" border=0></a></td> </tr><BR>


</table>
</html>


I needing to get the above code working properly or have it redone to work properly. I cannot get it figured out at all. The above code works properly if I remove the entire "Heading 2" block from the code.

thanks for any help...
Toby B.
Lead Mobo-fu Master
Lead Mobo-fu Master
 
Posts: 14277
Joined: Sun Dec 16, 2001 1:01 am
Location: Maine

help me out here a bit...

Postby tryn » Thu Aug 19, 2004 9:51 am

I'm not as deep into javascript as you appear to be, but I have a couple of questions.

What exactly are you trying to accomplish? Do you want the image to change when the OnMouseOver event occurs and that isn't working?

I can't replicate your page and troubleshoot as I don't have access to the style sheet or the images.

Shouldn't the <script> tags be in the <head> section?

Once I have a better idea of what is supposed to happen and what isn't happening, I may be able to help troubleshoot a bit. Do you have a URL I could go to and check out the page itself?

tryn
tryn
Initiate
Initiate
 
Posts: 85
Joined: Tue Mar 25, 2003 5:49 pm

Postby Toby B. » Thu Aug 19, 2004 12:59 pm

Will have a url availible later on this evening......I have moved the <script> block into the <head> tags as suggested and made no difference.

What exactly are you trying to accomplish? Do you want the image to change when the OnMouseOver event occurs and that isn't working?
What I am trying to accomplish is a universal code that I can adjust when needed to work with one or two rollover "instances". What I end up with now (when trying to have 2 rollover "instances"), is I roll the mouse over link/image 1 and link/image 2 lights up. When its just one link/image everything works flawlessly.. :roll:
Toby B.
Lead Mobo-fu Master
Lead Mobo-fu Master
 
Posts: 14277
Joined: Sun Dec 16, 2001 1:01 am
Location: Maine

Postby Toby B. » Thu Aug 19, 2004 2:17 pm

Toby B.
Lead Mobo-fu Master
Lead Mobo-fu Master
 
Posts: 14277
Joined: Sun Dec 16, 2001 1:01 am
Location: Maine

Postby hypnotik » Thu Aug 19, 2004 2:44 pm

I don't have time atm to error check your code, but this is the rollover script I use, if you want it. It's originally from dreamweaver, but found it to work well, so I use it even when hard coding.

This goes in the <head>
Code: Select all
<script language="JavaScript">
<!--
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>


Use the <body> tag to preload your rollover images:
Code: Select all
<body bgcolor="#FFFFFF" text="#000000" onLoad="MM_preloadImages('images/image_up.jpg')">


Then your img tag looks like this:
Code: Select all
<a href="link.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Rollover1','','images/image_up.jpg',1)"><img name="Rollover1" border="0" src="images/image_down.jpg"></a>
"I disapprove of what you say, but I will defend to the death your right to say it"

-Voltaire
hypnotik
Black Belt
Black Belt
 
Posts: 584
Joined: Tue Oct 22, 2002 9:07 pm
Location: Melbourne, Australia

Re: javascript help

Postby hypnotik » Thu Aug 19, 2004 2:53 pm

I think I just figured your problem: Both your images are named 'info'. Change the code for the second image to this, it should work:
Code: Select all
<a href="5bw1xx/5bw112/5BW112quickspecs.html" target="content"
onMouseOver="changeImg('info2',infoOn)"
onMouseOut="changeImg('info2',infoOff)">
<img name=info2 src="./../../images/getinfoup.gif" border=0></a>
"I disapprove of what you say, but I will defend to the death your right to say it"

-Voltaire
hypnotik
Black Belt
Black Belt
 
Posts: 584
Joined: Tue Oct 22, 2002 9:07 pm
Location: Melbourne, Australia

Postby Toby B. » Thu Aug 19, 2004 3:00 pm

ok thanks a bunch...

you don't happen to post over at webmaster-talk.com do you?

Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<BASE HREF="http://www.s87841630.onlinehome.us/">
<TITLE>Untitled</TITLE>
<link rel="STYLESHEET" type="text/css" href="common/cstechstyle.css">
<script language="JavaScript">
<!--
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array;

for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src;

x.src=a[i+2];}
}
//-->
</script>
</head>
<body bgcolor="#999999" text="white" link="white" vlink="white" alink="white"

onLoad="MM_preloadImages('/images/getinfodown.gif')">
<SCRIPT language="javascript1.1">

infoOn = new Image()
infoOn.src = "images/getinfodown.gif"

infoOff = new Image()
infoOff.src = "images/getinfoup.gif"

function changeImg(cImg,ref) {
document.images[cImg].src = ref.src
}
</SCRIPT>
<table width="100%" border="0">
<tr>
<td align="left" valign="top" class="submenuheading"><a href="sidenav.html"><font

color="yellow">Back</font></a></td>
</tr>
<tr>
<td height="50"></td>
</tr>
<tr>
<td align="center" valign="top" class="submenuheading">Quickspecs</td>
</tr>
<tr>
<td align="center" valign="top"> <a href="PC Theater/9100/9100quickspecs.html"

target="content"
onMouseOver="changeImg('info',infoOn)"
onMouseOut="changeImg('info',infoOff)"> </a><a

href="PC%20Theater/9100/sytemboard.html" onMouseOut="MM_swapImgRestore()"

onMouseOver="MM_swapImage('Image2','','/images/getinfodown.gif',1)"><img

name="Image2" border="0" src="/images/getinfoup.gif" width="103"

height="12"></a></td>
</tr>
<BR>
<BR>
<tr>
<td align="center" valign="top" class="submenuheading">Jumpers</td>
</tr>
<tr>
<td align="center" valign="top"> <a href="PC Theater/9100/sytemboard.html"

target="content"
onMouseOver="changeImg('info',infoOn)"
onMouseOut="changeImg('info',infoOff)"> <img name=info src="images/getinfoup.gif"

border=0></a></td>
</tr>
<BR>
</table>
</html>


That is what I got from a member there. Seems to work perfectly when the links are properly setup........... :oops:
When seting this above code up I failed to notice the BASE href. Thus throwing everything else off... :roll:

Between the two codes I should be good to go now... 8)
Toby B.
Lead Mobo-fu Master
Lead Mobo-fu Master
 
Posts: 14277
Joined: Sun Dec 16, 2001 1:01 am
Location: Maine

Postby hypnotik » Thu Aug 19, 2004 3:38 pm

Nah, that wasn't me :D

I guess that script is pretty popular thanks to dreamweaver. It works well across browsers, and preloads the images, which is what I like.

Hope it works out for ya.
"I disapprove of what you say, but I will defend to the death your right to say it"

-Voltaire
hypnotik
Black Belt
Black Belt
 
Posts: 584
Joined: Tue Oct 22, 2002 9:07 pm
Location: Melbourne, Australia

Postby Toby B. » Thu Aug 19, 2004 5:34 pm

Well except for rewriting a bunch of code things are starting to lookup for this project.... :D

thanks again for the help..
Toby B.
Lead Mobo-fu Master
Lead Mobo-fu Master
 
Posts: 14277
Joined: Sun Dec 16, 2001 1:01 am
Location: Maine


Return to Programming

Who is online

Users browsing this forum: No registered users and 3 guests

cron