PDA

View Full Version : using javascript to make subtopics on 3 navbar buttons


jv00123
10-31-2002, 10:27 PM
i want to use javascript on 3 of the .gif images on my navbar @ http://www.geocities.com/wwwkosdorg
the 3 are secondary schools , community sites and elementary schools. in particular, i wanted to have a box or something come out to the right of the buttons when rolled over so you can go over to the box and have a few subtopics to click on to go to that page. i cannot get any javascript to do this b/c i dont know javascript, so i was wondering if anyone can help me with coding this.

any help at all will be appreciated. thanks

Simrey
11-01-2002, 12:24 AM
OK, this is all a bit crude and only IE-friendly but have a go anyway -- looking at the site I see you haven't left yourself much time...

what I have done hastily is suggest for each topic a dynamically positioned div that will be hidden until you mouse over the relevant link. when you mouseout it should remain visible for three seconds, giving the user time to get the mouse over there and click something. I haven't had time to test it I'm afraid, but it looks ok....

You'll see I've created a showhide() function in the <script> area plus a set of string variables whose principle job is to avoid the proliferation of conficting quotes in the event calls.

One thing I notice is that you don't need to spell out the full url for documents or images on the same site, just the path from the current directory (the one conaing the current document). You'll see what I mean if you lok at the body tag. Or even if you look at it...

I also hav a feeling that tag ids and names shoudn't really have spaces in them, but that may be simple prejudice on my part.

<html>
<head>
<title>Keystone Oaks School District</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">
<!--



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];}
}

var delay=null, seco="secodiv", ele="elemdiv", comm="commdiv", empty="";
function showhide(d1,d2,d3) {
if(d1!="") eval("document.all."+d1+"style.visibility='visible';");
if(d2!="") eval("document.all."+d2+"style.visibility='hidden';");
if(d2!="") eval("document.all."+d3+"style.visibility='hidden';");
}
//-->
</script>
</head>

<body bgcolor="#FFFFFF" text="#000000" onLoad="MM_preloadImages('bar/bar2r.gif',
'bar2/bar3r.gif',
'bar2/bar4r.gif',
'navbar2/navbar1r.gif',
etc...)">
.....
html table tags etc...


<tr>
<td height="24" valign="top">
<a href="http://www.kosd.org/mainindexlinks/secondarylinkindex.html"
onMouseOut="MM_swapImgRestore();delay=setTimeout('showhide(empty,seco,empty)',3000);"
onMouseOver="clearTimeout(delay);MM_swapImage('2ndary schls','','navbar2/navbar9r.gif',1);showhide(seco,elem,comm);">
<img name="2ndaryschls" border="0" src="navbar/navbar9.gif" width="200" height="24"></a></td>
</tr>
...etc then

</table>

<div id="secodiv" style="position:absolute; left:250px; top:200px; visibility:hidden">
<a href="somedocument">Link text or image</a><br>
<a href="somedocument">Link text or image</a><br>
<a href="somedocument">Link text or image</a><br>
<a href="somedocument">Link text or image</a><br>
</div>
<div id="elemdiv" style="position:absolute; left:250px; top:300px; visibility:hidden">
<a href="somedocument">Link text or image</a><br>
<a href="somedocument">Link text or image</a><br>
<a href="somedocument">Link text or image</a><br>
<a href="somedocument">Link text or image</a><br>
</div>
<div id="commdiv" style="position:absolute; left:250px; top:400px; visibility:hidden">
<a href="somedocument">Link text or image</a><br>
<a href="somedocument">Link text or image</a><br>
<a href="somedocument">Link text or image</a><br>
<a href="somedocument">Link text or image</a><br>
</div>
</body>
</html>


Simon

jv00123
11-01-2002, 01:29 AM
ok thanks a lot, but can i just insert that into the existing index... if so, where should i put each part.. also, thanks for the advice on the tags and links.

im not gonna paste the index in here because its really long, so heres a link so you can just save it.... http://www.geocities.com/wwwkosdorg/index.html

Simrey
11-01-2002, 09:01 AM
Morning Jv00123,

Refreshed after my night's sleep I have had another look at my code and fixed a couple of things, and tested it and it's working now, though as I say I haven't had time to build in cross-browser compatability.

Obviously, you'll have to adjust the positions of the divs (not to mention the content!) to suit your purposes, but I have attached my version of your page to this post. Good luck...

jv00123
11-01-2002, 10:43 PM
Ok, thanks a lot , i changed everything around to suit the site and all, but i might change the pictures that i used for the java.
once again, thanks a lot for helping me with that, i appreciate it.