JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old July 7th, 2006, 09:20 PM
Akdor 1154 Akdor 1154 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Center Canyon in a Raptor
Posts: 34 Akdor 1154 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 28 m 44 sec
Reputation Power: 14
I feel like an idiot...

I'm pretty sure I'm missing something obvious here:

Code:
//javascript:
function menuClick(menuId) {
menuId.style.backgroundImage = "url(/images/skins/greeny/menubutton-down.png)";
}

function menuUnClick(menuId) {
menuId.style.backgroundImage = "url(/images/skins/greeny/menubutton.png)";
}

//Events

document.getElementById('menu0').onmousedown=menuC  lick(document.getElementById('menu0'));
document.getElementById('menu0').onmouseup=menuUnC  lick(document.getElementById('menu0'));
document.getElementById('menu0').onmouseout=menuUn  Click(document.getElementById('menu0'));
//menuClick etc. aren't broken up in my script, I think your board is playing up.
Code:
<!-- HTML -->
<ul id="menu">
    <li id="menu0">
      <a href="/index.php">Main Page</a>
    </li>
</ul>
Code:
/* CSS */
#menu li {
  list-style-type: none;
  float: left;
  background-image: url(/images/skins/greeny/menubutton.png);
}


It's meant to be a simple click-and-switch-bacground, but it Works Not. Using the HTML onLoad etc. attributes works, but then my code looks like ****. The CSS and JS are both external files.

Firefox:
Error: menuId has no properties
Source File: http://localhost/js/menu.js
Line: 7

Reply With Quote
  #2  
Old July 8th, 2006, 02:38 PM
Kravvitz Kravvitz is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2005
Location: USA
Posts: 140 Kravvitz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 1 h 33 m 14 sec
Reputation Power: 13
Looks like you're accessing the DOM before it's creation is complete. Do something like this:
Code:
window.onload = function() {
  document.getElementById('menu0').onmousedown= menuClick(document.getElementById('menu0'));
  document.getElementById('menu0').onmouseup= menuUnClick(document.getElementById('menu0'));
  document.getElementById('menu0').onmouseout= menuUnClick(document.getElementById('menu0'));
}

P.S. Many forum scripts break up long lines. It certainly is annoying when posting code.

Reply With Quote
  #3  
Old July 9th, 2006, 02:10 AM
Akdor 1154 Akdor 1154 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Center Canyon in a Raptor
Posts: 34 Akdor 1154 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 28 m 44 sec
Reputation Power: 14
Well, that fixed one problem, but now the function is called when, and only when, I refresh the page.

Thanks for your help though.

Reply With Quote
  #4  
Old July 9th, 2006, 09:27 PM
Kravvitz Kravvitz is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2005
Location: USA
Posts: 140 Kravvitz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 1 h 33 m 14 sec
Reputation Power: 13
That's odd. Perhaps there's another window.onload event handler that sometimes overrides this one.

Reply With Quote
  #5  
Old July 10th, 2006, 12:42 AM
ravs ravs is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2006
Location: gurgaon, haryana, india
Posts: 60 ravs User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 44 m 29 sec
Reputation Power: 13
Send a message via Yahoo to ravs
hey this code will never work
because the function you are trying to call on various events , they will automatically execute as soon as the window loads.

us something like this


window.onload = function() {
document.getElementById('menu0').onmousedown= function (){menuClick(document.getElementById('menu0'));}
}
Comments on this post
Kravvitz agrees!

Reply With Quote
  #6  
Old July 10th, 2006, 04:49 PM
Kravvitz Kravvitz is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2005
Location: USA
Posts: 140 Kravvitz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 1 h 33 m 14 sec
Reputation Power: 13
Wow. Thanks for catching my mistake, ravs.

You could also use the this keyword.
Code:
window.onload = function() {
  document.getElementById('menu0').onmousedown= function (){menuClick(this);}
}

Reply With Quote
  #7  
Old July 10th, 2006, 07:09 PM
Akdor 1154 Akdor 1154 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Center Canyon in a Raptor
Posts: 34 Akdor 1154 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 28 m 44 sec
Reputation Power: 14
It workses!
Ta muchly to all.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJavaScript Development > I feel like an idiot...


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap