/    Sign up×
Community /Pin to ProfileBookmark

JavaScript Function

Hello,

I desperately need some help with a JavaScript fucntion I am trying to get working. The function its self is below:

<script type=”text/javascript”>

function checkmenuitem()
{
var sPath = window.location.pathname;
var sPage = sPath.substring(sPath.lastIndexOf(‘/’) + 1);

if(sPage == “garden_bird_seed_blends.html” || sPage == “straight_birdseed_selections.html” || sPage == “softbill_foods.html” || sPage == “bird_fat_foods.html” || sPage == “live_bird_foods.html”){

document.getElementById(v-menu).style.display=”block”;

window.alert(“hello1”);
}

if(sPage == “bto_birdfeeders.html” || sPage == “droll_yankee_birdfeeders.html” || sPage == “nuttery_birdfeeders.html” || sPage == “general_birdfeeders.html” || sPage == “fat_food_birdfeeders.html” || sPage == “bird_tables_feeding_stations.html” || sPage == “bird_feeder_accessories.html” || sPage == “feeding_station_hangers.html”){

document.getElementById(v-menu2).style.display=”block”;

window.alert(“hello2”);
}

if(sPage == “wildlife_habitats.html” || sPage == “wildflower_seeds.html” || sPage == “wild_animal_foods.html” || sPage == “larger_birds.html” || sPage == “pond_care.html”){

document.getElementById(v-menu3).style.display=”block”;
}

if(sPage == “aviary_straight_bird_seeds.html” || sPage == “exotic_bird_seed_blends.html”){

document.getElementById(v-menu4).style.display=”block”;
}
}
</script>

I am triggering the function using the OnLoad property in the body tag as below:

<body onload=”checkmenuitem()”>

The idea bebind the function is to show the sub-menu sections of the navigation menu depending on which main section the user has clicked on – I have included a snippet of this below:

<a href=”#” class=”button” onclick=”javascript:showElement(‘v-menu’)”><h2>+ Garden Bird Food</h2></a>

<ul id=”v-menu” class=”v-menu” style=”display:none;”>
<li><a href=”garden_bird_seed_blends.html” title=”Garden Bird Food &amp Blends”>Garden Bird Food &amp Blends</a></li>
<li><a href=”straight_birdseed_selections.html” title=”Straight Bird Seed Selections”>Straight Bird Seed Selections</a></li>
<li><a href=”softbill_foods.html” title=”Softbill Foods”>Softbill Foods</a></li>
<li><a href=”bird_fat_foods.html” title=”Fat Foods”>Fat Foods</a></li>
<li><a href=”live_bird_foods.html” title=”Live Foods”>Live Foods</a></li>
</ul>

<div id=”divider”></div>

<a href=”#” class=”button” onclick=”javascript:showElement(‘v-menu2’)”><h2>+ Bird Feeders &amp Tables</h2></a>
<ul id=”v-menu2″ class=”v-menu2″ style=”display:none;”>
<li><a href=”bto_birdfeeders.html” title=”BTO Birdfeeders”>BTO Birdfeeders</a></li>
<li><a href=”droll_yankee_birdfeeders.html” title=”Droll Yankee Birdfeeders”>Droll Yankee Birdfeeders</a></li>
<li><a href=”nuttery_birdfeeders.html” title=”The Nuttery Birdfeeders”>The Nuttery Birdfeeders</a></li>
<li><a href=”general_birdfeeders.html” title=”General Birdfeeders”>General Birdfeeders</a></li>
<li><a href=”fat_food_birdfeeders.html” title=”Fat Food Birdfeeders”>Fat Food Birdfeeders</a></li>
<li><a href=”bird_tables_feeding_stations.html” title=”Bird Tables &amp Feeding Stations”>Bird Tables &amp Feeding Stations</a></li>
<li><a href=”bird_feeder_accessories.html” title=”Bird Feeder Accessories”>Bird Feeder Accessories</a></li>
<li><a href=”feeding_station_hangers.html” title=”Feeder Hangers &amp Hooks”>Feeder Hangers &amp Hooks</a></li>
</ul>

For some reason, I don’t think this function is even running.

Please Help!

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@mikewgdSep 01.2011 — Well, you dont have any function called showElement - so thats why they are not expanding.
Copy linkTweet thisAlerts:
@icebox68authorSep 01.2011 — Thanks Mike, but I do have a function for showElement which handles the actual display of the sub menu items. The function in question needs to keep that sub menu displayed if the page teh user visits represents one of the pages in the sub menu.
Copy linkTweet thisAlerts:
@mikewgdSep 01.2011 — Can I see that function?
Copy linkTweet thisAlerts:
@icebox68authorSep 01.2011 — Of course, here you go...

<script type="text/javascript">

function showElement(layer){

var myLayer = document.getElementById(layer);

document.cookie = document.getElementById(layer);

if(myLayer.style.display=="none"){

myLayer.style.display="block";

myLayer.backgroundPosition="top";

} else {

myLayer.style.display="none";

}

}

</script>
Copy linkTweet thisAlerts:
@mikewgdSep 01.2011 — You dont have quotes inside your document.getElementById(v-menu), there should be quotes. Try that.

http://mikewgd.com/wp-content/portfolio/JavaScript/test/Untitled-1.html (click on garden bird seed blends, and you will see the navigation will remain open.)
Copy linkTweet thisAlerts:
@icebox68authorSep 01.2011 — Thank you so much - it works fine now :-)

How stupid of me to have missed that!
Copy linkTweet thisAlerts:
@mikewgdSep 01.2011 — No problem. Hey! It happens!!
×

Success!

Help @icebox68 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...