11548 sujets

JavaScript, DOM et API Web HTML5

On behalve of an previous topic I opened on one of these pages on this forum, in wich one problem is solved, I now open up a new topic wich issues the second problem wich I gladly would like to see solved, it's this: (The first problem is solved in here: http://forum.alsacreations.com/topic-23-10114-1-ANGLAIS-Problems-With-A-JavascriptCSS-vertical-Dropdown-Menu.html )

"First off all I would like to say that I don't know any more French than "Je n'ai comprend pas, tu parlez Anglais?? No? Tu Zut..." (and I HOPE this isn't taken wrong when I say that to a French person If you know what I mean!). And most of the time it's enough for me as a Dutch person, altough I know my Englisch, and I will try to see if someone here knows it to who can help me, cause I already mailed this to the webmaster, but he is to busy to help me, and sugested me to put it on the forum here, altough that is in French, I try to see how far I come with navigating in here, cause I also have a PHPbb Forum on one of my servers... But please every respons in here in Englisch, cause I don't understand French (and you might have seen in my only full French sentence I know!)

Well, now the problem:

I have 1 question (left) about a CSS and (X)HTML drop-down (vertical and
horizontal) menu wich is explained in Englisch
(http://tutorials.alsacreations.com/deroulant/) on one of the pages on
this website. I am trying to customise the vertical dropdown menu to my needs, just similar like the one located on www.henkhouben.nl/Test has. Only, you might have seen, that menu is not working 100%, and I've been working with this one for more than 1 year now, but I can't seem to fix it right! So after a long search I found this very similar menu from this website....

The problem:
When on www.henkhouben.nl/Test you see >-images but when you openup a menu, the image changes, and when you open up another menu (like this new menu also does, that is one of the key-features to me!), the image changes back.
Could this also be made applieable to this menu??? If so, could someone tell me (or do for me) how to customise that so it does exactly what the menu on www.henkhouben.nl/Test does???

- I putted the menu as it is now on the net here http://www.henkhouben.nl/Test3 and
- the menu witch was as I had edited it, is located here:
http://www.henkhouben.nl/Test2
So you can see the changes cq. can visualise the whole!
- http://www.henkhouben.nl/Test still is the old one!

the total code for this one-page-multiple-frame-menu (to call it like that!) as it is now, is as followed:

a écrit :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>MenuFrame</title>
<script type="text/javascript">
<!--
window.onload=show;
function show(id) {
var d = document.getElementById(id);
for (var i = 1; i<=10; i++) {
if (document.getElementById('smenu'+i)) {document.getElementById('smenu'+i).style.display='none';}
}
if (d) {d.style.display='block';}
}
//-->
</script>
<style type="text/css" media="screen">
<!--
body {
margin: 0;
padding: 0;
background: black;
font: 70% verdana, arial, sans-serif;
}
dl, dt, dd, ul, li {
margin: 0;
padding: 0;
list-style-image:url(images/bullet.gif); /* replacing/your your bullets */
}
#menu {
position: absolute; /* Menu position that can be changed at will */
top: 77px;
left: 20px;
}
#menu {
width: 20em;
}
#menu dt {
cursor: pointer;
margin: 2px 0;;
height: 20px;
line-height: 20px;
text-align: left;
font-weight: bold;
border: 1px Black;
background: black;
}
#menu dd {
border: 1px Black;
}
#menu li {
text-align: left;
margin-left:2em;
background: black;
}
#menu li a, #menu dt a {
color: #fff;
text-decoration: none;
display: block;
border: 0 none;
height: 100%;
}
#menu li a:hover, #menu dt a:hover {
background: black;
}
.style1 {color: #FFFFFF}
dt span, dt a { background:url(images/closed.gif) left bottom no-repeat;padding-left:30px;} /* using you open image */
--></style>
</head>
<body>
<dl id="menu">
<dt onclick="javascript:show();"><a href="mainFrame.html" target="mainFrame">Home</a></dt>
<dt onclick="javascript:show('smenu2');">
<span class="style1">Maastricht</span></dt>
<dd id="smenu2">
<ul>
<li class="style1">
<a href="pages/page1.html" target="mainFrame">&nbsp;&nbsp;Page 1</a></li>
<li class="style1">
<a href="pages/page2.html" target="mainFrame">&nbsp;&nbsp;Page 2</a></li>
<li class="style1">
<a href="pages/page3.html" target="mainFrame">&nbsp;&nbsp;Page 3</a></li>
</ul>
</dd>
<dt onclick="javascript:show('smenu3');">
<span class="style1">Events</span></dt>
<dd id="smenu3">
<ul class="style1">
<li>
<a href="pages/page4.html" target="mainFrame">&nbsp;&nbsp;Page 4</a></li>
<li>
<a href="pages/page5.html" target="mainFrame">&nbsp;&nbsp;Page 5</a></li>
<li>
<a href="pages/page6.html" target="mainFrame">&nbsp;&nbsp;Page 6</a></li>
</ul>
</dd>
<dt onclick="javascript:show('smenu4');">
<span class="style1">Travel</span></dt>
<dd id="smenu4">
<ul>
<li class="style1">
<a href="pages/page7.html" target="mainFrame">&nbsp;&nbsp;Page 7</a></li>
<li class="style1">
<a href="pages/page8.html" target="mainFrame">&nbsp;&nbsp;Page 8</a></li>
<li class="style1">
<a href="pages/page9.html" target="mainFrame">&nbsp;&nbsp;Page 9</a></li>
</ul>
</dd>
<dt onclick="javascript:show('smenu5');">
<span class="style1">Sphinx</span></dt>
<dd id="smenu5">
<ul>
<li class="style1">
<a href="pages/page10.html" target="mainFrame">&nbsp;&nbsp;Page 10</a></li>
<li class="style1">
<a href="pages/page11.html" target="mainFrame">&nbsp;&nbsp;Page 11</a></li>
<li class="style1">
<a href="pages/page12.html" target="mainFrame">&nbsp;&nbsp;Page 12</a></li>
</ul>
</dd>
<dt onclick="javascript:show('smenu6');">
<span class="style1">Diversity</span></dt>
<dd id="smenu6">
<ul>
<li class="style1">
<a href="pages/page13.html" target="mainFrame">&nbsp;&nbsp;Page 13</a></li>
<li class="style1">
<a href="pages/page14.html" target="mainFrame">&nbsp;&nbsp;Page 14</a></li>
<li class="style1">
<a href="pages/page15.html" target="mainFrame">&nbsp;&nbsp;Page 15</a></li>
</ul>
</dd>
<dt onclick="javascript:show('smenu7');">
<span class="style1">Author</span></dt>
<dd id="smenu7">
<ul>
<li class="style1">
<a href="pages/PhotographerHH.html" target="mainFrame">&nbsp;&nbsp;Photographer</a></li>
<li class="style1">
<a href="pages/PhotographerHHNL.html" target="mainFrame">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Dutch
Translation</a></li>
<li class="style1">
<a href="pages/CreatorMH.html" target="mainFrame">&nbsp;&nbsp;Creator</a></li>
<li class="style1">
<a href="pages/CreatorMHNL.html" target="mainFrame">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Dutch
Translation</a></li>
</ul>
</dd>
<dt onclick="javascript:show('smenu8');">
<span class="style1">Links</span></dt>
<dd id="smenu8">
<ul>
<li class="style1">
<a href="http://www.google.nl" target="_blank">&nbsp;&nbsp;Google</a></li>
<li class="style1">
<a href="http://www.clubcharts.nl" target="_blank">&nbsp;&nbsp;Clubcharts</a></li>
<li class="style1">
<a href="http://www.djdadevil.com" target="_blank">&nbsp;&nbsp;Dj Da Devil</a></li>
</ul>
</dd>
<dt onclick="javascript:show('smenu9');">
<span class="style1">Contact</span></dt>
<dd id="smenu9">
<ul>
<li class="style1">
<a href="mailto:henk@henkhouben.nl">&nbsp;&nbsp;E-Mail</a></li>
</ul>
</dd>
</dl>
</body>
</html>


I hope someone understands this and is able to help me....

untill then, I already wanna thank the one who is able to help me, and untill then, I remain...

Your Sincerrely,

Mark
Pays Bas
Edited by djdadevil (15 Jan 2006 - 13:24)
I,
This is a quick, ugly and not tested solution :

In each span "title" of the menu, you add an id containing a prefix (bullet) and the number of the sub-menu eg:bullet2,bulllet3 ...

You also need to change the variable pass by the function "show"
show('smenu2')->show('2')
show('smenu3')->show('3')
...


<dt onclick="javascript:show('2');">
		<span class="style1" id="bullet2">Maastricht</span></dt>
	<dd id="smenu2">
		<ul>
			<li class="style1">

				<a href="pages/page1.html" target="mainFrame">  Page 1</a></li>
			<li class="style1">
				<a href="pages/page2.html" target="mainFrame">  Page 2</a></li>
			<li class="style1">
				<a href="pages/page3.html" target="mainFrame">  Page 3</a></li>
		</ul>
	</dd>

	<dt onclick="javascript:show('3');">
		<span class="style1" id="bullet3">Events</span></dt>
	<dd id="smenu3">
		<ul class="style1">
			<li>
				<a href="pages/page4.html" target="mainFrame">  Page 4</a></li>
			<li>
				<a href="pages/page5.html" target="mainFrame">  Page 5</a></li>

			<li>
				<a href="pages/page6.html" target="mainFrame">  Page 6</a></li>
		</ul>
	</dd>
	<dt onclick="javascript:show('4');">
		<span class="style1"  id="bullet4">Travel</span></dt>
	<dd id="smenu4">
...	
	


In your script you must change
var d = document.getElementById(id);
to
var d = document.getElementById('smenu'+id);
(because now we use show('2') instead of show('smenu2'))

Then in your script, first you set all the background-image of the span to "closed.gif" (document.getElementById('bullet'+i).style.background='url(images/closed.gif)';)

then for the selected menu you set the background-image of the span to "open.gif" (document.getElementById('bullet'+i).style.background='url(images/open.gif)') :

<script type="text/javascript">
<!--
window.onload=show;
function show(id) {
var d = document.getElementById('smenu'+id);
	for (var i = 1; i<=10; i++) 
	{
		if (document.getElementById('smenu'+i)) 
			{
				document.getElementById('smenu'+i).style.display='none';
			}
		//set "closed"	for all the bullets
		if (document.getElementById('bullet'+i)) 
			{
				document.getElementById('bullet'+i).style.background='url(images/closed.gif)';
			}	
			
	}
	if (d) 
	{
		d.style.display='block';
		document.getElementById('bullet'+i).style.background='url(images/open.gif)'
	}
}
//-->
</script>



good luck !
Hello,

I performed all the things you said, and no, I found it not ugly, I could get wise out of it, and that's due to your excelent explaination of each item, thank you! But look at it now (cause ofcource, I tested it for you!)
http://www.henkhouben.nl/Test3 ...

Do you see what's happened now?...

Maybe wise to know...(Cause I didn't quite get how you specified an id to an image (e.g. you say, use id="bullet2" and in the next span class you use id="bullet3" etc!) all images are in a folder named 'images' the image for the standard thick bullet = 'closed.gif' ; the image for the standard small bullet in the submenu's = 'bullet.gif' and the image wich I want to see when a specific submenu is openend = 'open.gif'.... Maybe something you need...

But alright, look at the results, and maybe you see what's still 'wrong' (Cause I stick with Actionscripting, and feel as a total noob with other programming languages nowadays... (except HTML, but alright, I don't know all the functions out of my head!)). Hope you (or someone else) sees how he/sche can help me with this!

Thank you already anaway,

Your sincerrely,

Mark
Pays Bas
Edited by djdadevil (06 Jan 2006 - 13:55)
Modérateur
hi,
<fr> en français au bas du post , merci </fr>
<edit>oups !! basicly , similar idea than fxoxo !! </edit>
So i come again, with maybe the solution after all ?
Not any good in javascript i made little change to make it work, (it's more like 101 , based on the original script itself.).

So to make it work, i change the "calling function " smenux to x (smenu2 becomes 2 ),
add an "id" to each "<dt>" (and the first "<a>") as bg1 and so on ..

From that i get from the "clickevent" a number (from 1 to 9 in your page as it is preset). and then i reused to original script twice with 2 "var" instead of one : "d" & "e" .
that give me the possibilite to point at two specifics elements at once.

I have no idea if this would be the best method or if it's bugless, but it works on my computer.

I have also change, some of the html part, and the last bit of css (just the background image, open.gif).
It's overwritten by the the javascript if enable.
So here the page again (take the whole thing maybe Smiley smile )
(oh by the way ,dank u voor less 1 Smiley cligne )
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
		<title>Untitled Document</title>
		<script type="text/javascript">
<!--
window.onload=show;
function show(id) {

var d = document.getElementById('smenu'+id);
var e = document.getElementById('bg'+id);/* new line */

	for (var i = -1; i<=10; i++) {
		if (document.getElementById('smenu'+i)) {
document.getElementById('smenu'+i).style.display='none';
document.getElementById('bg'+i).style.background='url(http://www.henkhouben.nl/Test/images/closed.gif) left bottom no-repeat';/*new line  */
}
document.getElementById('smenu1').style.display='block';/*new line , not to erase home menu */
	}
if (d) {
d.style.display='block'; 
e.style.background='url(http://www.henkhouben.nl/Test/images/open.gif) left top no-repeat ';/*new line  */

}

}




//-->
		</script>
		<style type="text/css" media="screen">
/* Edited with EditCSS */
/**** Inline STYLE-tag style sheet ****/
			<!-- 
body {
margin: 0;
padding: 0;
background: black;
font: 70% verdana, arial, sans-serif;
}
dl, dt, dd, ul, li {
margin: 0;
padding: 0;
list-style-image:url(http://www.henkhouben.nl/Test/images/bullet.gif);/* replacing/your your bullets */
}

#menu {
position: absolute; /* Menu position that can be changed at will */
top: 77px;
left: 20px;
}

#menu {
width: 20em;
}

#menu dt {
cursor: pointer;
margin: 2px 0;;
height: 20px;
line-height: 20px;
text-align: left;
font-weight: bold;
border: 1px Black;
background: black;
}



#menu dd {
border: 1px Black;
}

#menu li {
text-align: left;
margin-left:2em;
background: black;
}

#menu li a, #menu dt a {
color: #fff;
text-decoration: none;
display: block;
border: 0 none;
height: 100%;
}

#menu li a:hover, #menu dt a:hover {

}

.style1 {color: #FFFFFF}

dt span, dt a { background:url(http://www.henkhouben.nl/Test/images/open.gif) left bottom no-repeat;padding-left:30px;} /* using you open 

image */

--></style>

	</head>
	<body>
		<dl id="menu">
			<dt onclick="javascript:show('1'); "id="smenu1"><a href="mainFrame.html" target="mainFrame" id="bg1" >Home</a></dt>
			<dt onclick="javascript:show('2');">
				<span class="style1" id="bg2">Maastricht</span></dt>
			<dd id="smenu2">
				<ul>
					<li class="style1">
						<a href="pages/page1.html" target="mainFrame">&nbsp;&nbsp;Page 1</a></li>
					<li class="style1">
						<a href="pages/page2.html" target="mainFrame">&nbsp;&nbsp;Page 2</a></li>
					<li class="style1">
						<a href="pages/page3.html" target="mainFrame">&nbsp;&nbsp;Page 3</a></li>
				</ul>
			</dd>
			<dt onclick="javascript:show('3');">
				<span class="style1" id="bg3">Events</span></dt>
			<dd id="smenu3">
				<ul class="style1">
					<li>
						<a href="pages/page4.html" target="mainFrame">&nbsp;&nbsp;Page 4</a></li>
					<li>
						<a href="pages/page5.html" target="mainFrame">&nbsp;&nbsp;Page 5</a></li>
					<li>
						<a href="pages/page6.html" target="mainFrame">&nbsp;&nbsp;Page 6</a></li>
				</ul>
			</dd>
			<dt onclick="javascript:show('4');">
				<span class="style1" id="bg4">Travel</span></dt>
			<dd id="smenu4">
				<ul>
					<li class="style1">
						<a href="pages/page7.html" target="mainFrame">&nbsp;&nbsp;Page 7</a></li>
					<li class="style1">
						<a href="pages/page8.html" target="mainFrame">&nbsp;&nbsp;Page 8</a></li>
					<li class="style1">
						<a href="pages/page9.html" target="mainFrame">&nbsp;&nbsp;Page 9</a></li>
				</ul>
			</dd>
			<dt onclick="javascript:show('5');">
				<span class="style1" id="bg5">Sphinx</span></dt>
			<dd id="smenu5">
				<ul>
					<li class="style1">
						<a href="pages/page10.html" target="mainFrame">&nbsp;&nbsp;Page 10</a></li>
					<li class="style1">
						<a href="pages/page11.html" target="mainFrame">&nbsp;&nbsp;Page 11</a></li>
					<li class="style1">
						<a href="pages/page12.html" target="mainFrame">&nbsp;&nbsp;Page 12</a></li>
				</ul>
			</dd>
			<dt onclick="javascript:show('6');">
				<span class="style1" id="bg6">Diversity</span></dt>
			<dd id="smenu6">
				<ul>
					<li class="style1">
						<a href="pages/page13.html" target="mainFrame">&nbsp;&nbsp;Page 13</a></li>
					<li class="style1">
						<a href="pages/page14.html" target="mainFrame">&nbsp;&nbsp;Page 14</a></li>
					<li class="style1">
						<a href="pages/page15.html" target="mainFrame">&nbsp;&nbsp;Page 15</a></li>
				</ul>
			</dd>
			<dt onclick="javascript:show('7');">
				<span class="style1"  id="bg7">Author</span></dt>
			<dd id="smenu7">
				<ul>
					<li class="style1">
						<a href="pages/PhotographerHH.html" target="mainFrame">&nbsp;&nbsp;Photographer</a></li>
						<li class="style1">
						<a href="pages/CreatorMH.html" target="mainFrame">&nbsp;&nbsp;Creator</a></li>
				</ul>
			</dd>
			<dt onclick="javascript:show('8');">
				<span class="style1" id="bg8">Links</span></dt>
			<dd id="smenu8">
				<ul>
					<li class="style1">
						<a href="http://www.google.nl" target="_blank">&nbsp;&nbsp;Google</a></li>
					<li class="style1">
						<a href="http://www.clubcharts.nl" target="_blank">&nbsp;&nbsp;Clubcharts</a></li>
					<li class="style1">
						<a href="http://www.djdadevil.com" target="_blank">&nbsp;&nbsp;Dj Da Devil</a></li>
				</ul>
			</dd>
			<dt onclick="javascript:show('9');">
				<span class="style1" id="bg9">Contact</span></dt>
			<dd id="smenu9">
				<ul>
					<li class="style1">
						<a href="mailto:henk@henkhouben.nl">&nbsp;&nbsp;E-Mail</a></li>
				</ul>
			</dd>
		</dl>
	</body>
</html>


Hopefully , it will work for you too.
Usually, i don't like much javascripting, cause i very often get my browsers going nuts or freezing ....

<fr>
bonjour,
en partant sur le javascript de base, et en changeant l'appel de la fonction, je reutilise basiquement le meme script.
l'appel a la fonction show('smenu2') par exemple devient show('2').

je donne une id a chaque dt (terminé avec un numero)
de ce fait je peut pointe sur 2 balises nommé par Id a chaque click.
Le resultat escompté est obtenu .

N'etant pas a l'aise avec le javascript , peut-etre quelqu'un de plus qualifie pourrait corriger ce script si besoin ?

<edit>oups !! idée sur la meme base que fxoxo !! </edit></fr>

au revoir
Modifié par gcyrillus (06 Jan 2006 - 23:11)
Yes GCyrillus!!!

It works like a charm, just like the first solution you gave to me in the other topic... the resulst are located here http://www.henkhouben.nl/Test3 ...

If it's the best method, I also can't say, but if it works I'm glad!!!

Thanks for the whole thing hehe, didn't take me much time to see te differences like this hehe... But alright, am glad this is sorted out Smiley lol Now finally a fully functional-and-custom-frame-page-javascript-tree-menu (something else than Flash wich I usually use for that, but some customers don't want to use Flash as navigator, they believe that my license doesn't work for them (but in real time, I've got a license, and may publish own Flash work everywhere on the net, and those customers just don't believe it, but alright,) I happy, they happy, everyone happy!!!)

2-ALL A BIG THANKS AGAIN!!! AND GOOD LUCK WITH YOUR CAREERS...

GCyrillus; 'Geen Dank' Smiley cligne (je vous en prie! if I'm correct?) And it's written 'Dank u voor les 1' Smiley cligne :) 'Dank U!' (Remerciement VOUS!) But than again, everty Dutch man or woman understands that to!!! Good luck and MAYBE till some time....

Your sincerrely, and great gratitute from,

Mark aux Pays Bas!
Modérateur
hello,

oups, having a look from your link , i realized that it was bugging a bit Smiley confused with firefoxe.
once you clikc on a link the menu slides on the left, hidding the bullets, and the right frame stays white.
For some reasons i don't get (for the frame not being updated under Firefoxe mainly) its seems that css rule :
#menu {
width:20em;
}

is involved ....

cause i first change it to
#menu {
width:180px;
}

to test if that was enough to avoid the menu to slide, it worked but all the sudden the right frame was updated !?!!...
That's a mystery for me, I guess the javascript used might not be the best method... if anyone has any other solution more efficient, it 'll be welcome.

dank u voor les 2, glad you don't hear me trying talking dutch, i'm afraid my spelling is better , ... allo allo "caricature".

tot so...
gcyrillus a écrit :
hello,

oups, having a look from your link , i realized that it was bugging a bit Smiley confused with firefoxe.
once you clikc on a link the menu slides on the left, hidding the bullets, and the right frame stays white.
For some reasons i don't get (for the frame not being updated under Firefoxe mainly) its seems that css rule :
#menu {
width:20em;
}

is involved ....

cause i first change it to
#menu {
width:180px;
}

to test if that was enough to avoid the menu to slide, it worked but all the sudden the right frame was updated !?!!...
That's a mystery for me, I guess the javascript used might not be the best method... if anyone has any other solution more efficient, it 'll be welcome.

dank u voor les 2, glad you don't hear me trying talking dutch, i'm afraid my spelling is better , ... allo allo "caricature".

tot so...


Well I've changed it, but am not able to test it in any other browser than IE, cause I only use that one and not Firefox or any other browser, cause that might f*ck up my system wich I use for programming with specific codes if you know what I mean! But it's changed to px instead of em maybe that solved the problem for you,

Take a look and be free to test it out at www.henkhouben.nl cause today I've released a bit of it!

Geen dank voor les 2 Smiley cligne (No thanks for lesson number 2)... Jou Nederlands gaat goed vooruit... (Your Dutch is going good forward...). en wie weet zie ik u nog wel eens in ons landje... (and maybe I will see you in our small country...).... voor nu, alweer bedankt en tot 'ziens'... (for now, again thank you and 'goodbye'...) Smiley lol

Your sincerely,

Mark de Maastricht aux Pays Bas Smiley biggol
Modérateur
hi,
Yes, it's now working fine on my computer. Smiley smile .
tot ziens, mischien ..

maybe you can edit the title of your post with a [RESOLU] up front, this topic might be useful for others

Smiley cligne

take care.
gcyrillus a écrit :
hi,
Yes, it's now working fine on my computer. Smiley smile .
tot ziens, mischien ..

maybe you can edit the title of your post with a [RESOLU] up front, this topic might be useful for others

Smiley cligne

take care.


Nice Smiley smile ... and I also edited the title Smiley cligne

Maybe tot ziens yes!

Bye Bye