...

View Full Version : javascript



AAOROE
10-24-2006, 01:47 PM
I have a website with navigational links. They are javascript, some of them you will click and sub menus will drop. Below are my questions

1) Is there a way that if you click one button with sub menus that you can click it again and it will minimize the sub menus

2)With javascript a button that has javascript is there a way that you can click on the main menu button open a new page & open up the sub menus?

3)With javascript can you have sub sub-menus like this...?
Main Button
Sub Menu 1
Sub Menu 2
Sub Sub-Menu 1

Thanks for your help?

Those links are at www.pctthinktank.org/wboy

Thanks

Michael Brown

Kor
10-24-2006, 03:46 PM
The answer to all your questions is yes. The precise answers (ie some examples) are up the code you have. It is rather a personalized solution, not quite a general one.

radnor
10-24-2006, 04:43 PM
The answer to #1 is:


<script type="text/javascript">
<!--
window.onload=show;
function show(id) {
var d = document.getElementById(id);
var vis;

for (var i = 1; i<=10; i++) {
if (document.getElementById('smenu'+i)) {document.getElementById('smenu'+i).style.display='none';}
}

vis = d.style.display;

if (vis == 'block') {
d.style.display='none';}
else {
d.style.display='block';}
}
//-->
</script>


I initially added a CLASS to the sub menus with a property of "display:none". But for the display/hide part to work you initially had to DOUBLE click the button ONE time. This set the DISPLAY as either none or block which passed the if stmnt. By going through you ORIGINAL code, this set the initial value which we could toggle.


And as the poster above said, if you found this to be helpful, some rep points would be great!!!

Have a good day!
Radnor

radnor
10-24-2006, 04:48 PM
This code... If you click on memberships (with sub menu) will display it (subm). Then if you click it again it's closed then reopened. If however, you click a DIFFERENT submenu, the original closes and the new one will open.

The way around this is on load, assign them a status (YOUR ORIGINAL FOR LOOP). Then make my code a simple toggle.

radnor
10-24-2006, 04:52 PM
But... This brings us a new problem.... If we open memberships then adult programs, BOTH stay open.


window.onload=noshow;
function noshow() {

for (var i = 1; i<=10; i++) {
if (document.getElementById('smenu'+i)) {document.getElementById('smenu'+i).style.display='none';}
}
}

function show(id) {
var d = document.getElementById(id);
var vis;


vis = d.style.display;

if (vis == 'block') {
d.style.display='none';}
else {
d.style.display='block';}
}
//-->

radnor
10-24-2006, 05:23 PM
And the final script to make it all happen is:


window.onload=noshow;
function noshow() {

for (var i = 1; i<=10; i++) {
if (document.getElementById('smenu'+i)) {
document.getElementById('smenu'+i).style.display='none';
}
}
}

function show(id) {
var d = document.getElementById(id);
var vis;

vis = d.style.display;

if (vis == 'block') {
d.style.display='none';
} else {
d.style.display='block';
}

for (var i = 1; i<=10; i++) {
if (id.substr(-1,1) != i) {
document.getElementById('smenu'+i).style.display='none';
}
}
}

AAOROE
10-24-2006, 06:34 PM
If I am correct all this goes into the head? Dont worry you will get reconizitioj (sp) when used

Thanks

Mike

radnor
10-24-2006, 06:48 PM
Yes, your current script is JUST after the TITLE tag. Replace yours with mine.

Now, NEVER take anyones word for it. Make a BACKUP copy FIRST! Test it make sure it is what you are looking for. I tested it in FF. I do not use IE, so I dont know about it.

Radnor

AAOROE
10-24-2006, 06:50 PM
okay thanks for your help dude My friend gave me his copy of a menu maker. Umm so I have to check if they want this or the version my friend gave me. Either way it was very helpful and appriciative. This will show me how to use it in the future if they dont like it. lol.

Thanks again

Mike



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum