Connecting Tech Pros Worldwide Forums | Help | Site Map

Some help with dropdown menus

Newbie
 
Join Date: Mar 2008
Posts: 3
#1: Mar 4 '08
Hi, I have just joined the forum and I need help with Javascrip dropdown menus. I have written a function which should change the background image of a button when it is clicked:

function change(el)
{

if (el.style.background='url(arrow-up-title2.jpg)'){
el.style.background='url(arrow-down-title2.jpg)'
}

if (el.style.background='url(arrow-down-title2.jpg)'){
el.style.background='url(arrow-up-title2.jpg)'
}


}


The problem is the background only changes once. When I click on the main menu the background is originally arrow-down-title2.jpg and this changes to arrow-up-title2.jpg but when I click the menu again it does not change back to arrow-down-title2.jpg.

Does anyone have an idea why?

This is how I pass my parameter:

<div id="menu" onclick="change(this);SwitchMenu('sub1')">Menu</div>

debasisdas's Avatar
Moderator
 
Join Date: Dec 2006
Location: Bangalore ,India
Posts: 7,511
#2: Mar 4 '08

re: Some help with dropdown menus


Question moved to Javascript forum.
hsriat's Avatar
Expert
 
Join Date: Jan 2008
Location: Bath, UK
Posts: 1,609
#3: Mar 4 '08

re: Some help with dropdown menus


Expand|Select|Wrap|Line Numbers
  1. var bg = 0;
  2. function change(el) {
  3.     el.style.background = bg ? 'url(arrow-down-title2.jpg)' : 'url(arrow-up-title2.jpg)';
  4.     bg = !bg;
  5. }
Newbie
 
Join Date: Mar 2008
Posts: 3
#4: Mar 4 '08

re: Some help with dropdown menus


Quote:

Originally Posted by hsriat

Expand|Select|Wrap|Line Numbers
  1. var bg = 0;
  2. function change(el) {
  3.     el.style.background = bg ? 'url(arrow-down-title2.jpg)' : 'url(arrow-up-title2.jpg)';
  4.     bg = !bg;
  5. }

Wow, it works. Thank you so much !!!!!!!!!!!!!!!!!!!!!!!!!!!
Reply


Similar JavaScript / Ajax / DHTML bytes