HTML, JavaScript And CSS Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingHTML, JavaScript And CSS Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now!
  #1  
Old March 27th, 2008, 03:27 PM
cjreynolds cjreynolds is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 351 cjreynolds User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 10 h 9 m 21 sec
Reputation Power: 4
HTML - Using Named Images in HTML

I have a page with rollover buttons for navigation.

I usually use straight HTML to do rollovers:

Code:
<A HREF="http://www.ntsbdc.org/default.asp"><IMG ID="btnHome" SRC="images/btn_home_wht.jpg" BORDER="0" onMouseOver="this.src='images/btn_home.jpg'" onMouseOut="this.src='images/btn_home_wht.jpg'"></A>


Instead, I'd like to name the button images in JS:

Code:
if (document.images)
{
	btnHomeWhite= new Image(53,23); btnHomeWhite.src="images/btn_home_wht.jpg"; btnHomeBlue= new Image(53,23); btnHomeBlue.src="images/btn_home.jpg";
	btnAboutWhite= new Image(70,25); btnAboutWhite.src="images/btn_about_wht.jpg"; btnAboutBlue= new Image(70,25); btnAboutBlue.src="images/btn_about.jpg";
	btnServicesWhite= new Image(90,25); btnServicesWhite.src="images/btn_services_wht.jpg"; btnServicesBlue= new Image(90,25); btnServicesBlue.src="images/btn_services.jpg";
	btnLocalWhite= new Image(55,25); btnLocalWhite.src="images/btn_local_wht.jpg"; btnLocalBlue= new Image(55,25); btnLocalBlue.src="images/btn_local.jpg";
	btnCalendarWhite= new Image(43,25); btnCalendarWhite.src="images/btn_calendar_wht.jpg"; btnCalendarBlue= new Image(43,25); btnCalendarBlue.src="images/btn_calendar.jpg";
	btnSuccessWhite= new Image(105,25); btnSuccessWhite.src="images/btn_success_wht.jpg"; btnSuccessBlue= new Image(105,25); btnSuccessBlue.src="images/btn_success.jpg";
		
}


then use something like this:
Code:
<A HREF="http://www.ntsbdc.org/default.asp"><IMG ID="btnHome" SRC=btnHomeWhite BORDER="0" onMouseOver="this.src=btnHomeBlue" onMouseOut="this.src=btnHomeWhite"></A>


Of course, this syntax doesn't work - Does anyone know if this can be done?

joe

Reply With Quote
  #2  
Old March 28th, 2008, 04:35 AM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
Click here for more information.
 
Join Date: Sep 2004
Location: Israel
Posts: 26,621 Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)  Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 4 Days 13 h 47 m 29 sec
Reputation Power: 1441
most simple way that I can think of is:
Code:
<img id="btnHome" onload="this.src = btnHomeWhite.src;" border="0" onmouseover="this.src = btnHomeBlue.src;" onmouseout="this.src = btnHomeWhite.src;" />

not sure it will work but it's worth a shot.. also please use Fiddler or some
other HTTP sniffer to make sure this does not send page request due to
the blank image.. if it does you can create small dummy image then:
Code:
<img src="pixel.gif" id="btnHome" onload="this.src = btnHomeWhite.src;" border="0" onmouseover="this.src = btnHomeBlue.src;" onmouseout="this.src = btnHomeWhite.src;" />

and pixel.gif will be one pixel image.

Reply With Quote
  #3  
Old April 1st, 2008, 10:45 AM
cjreynolds cjreynolds is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 351 cjreynolds User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 10 h 9 m 21 sec
Reputation Power: 4
No good - I get a broken image icon. If I include the onload parameter and the "src='image.jpg'" both in the same line, I get a "stack overflow" error.

Reply With Quote
  #4  
Old April 1st, 2008, 10:47 AM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
Click here for more information.
 
Join Date: Sep 2004
Location: Israel
Posts: 26,621 Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)  Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 4 Days 13 h 47 m 29 sec
Reputation Power: 1441
if you change this to:
Code:
onload="alert(btnHomeWhite.src);"

what do you see in the alert?

Reply With Quote
  #5  
Old April 1st, 2008, 11:11 AM
cjreynolds cjreynolds is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 351 cjreynolds User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 10 h 9 m 21 sec
Reputation Power: 4
I change the line to:
Code:
<A HREF="http://www.ntsbdc.org/default.asp"><IMG ID="btnHome" onload="alert(btnHomeWhite.src);" BORDER="0" onMouseOver="this.src = btnHomeBlue.src;" onMouseOut="this.src = btnHomeWhite.src;"/></A>

the alert doesn't come up until I mouse over the button - then I get "http://localhost/sbdc/images/btn_home_wht.jpg" and I get the same alert when mousing out (no more stack overflow errors).

Reply With Quote
  #6  
Old April 1st, 2008, 11:16 AM
cjreynolds cjreynolds is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 351 cjreynolds User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 10 h 9 m 21 sec
Reputation Power: 4
Also, if I use onload="alert(this.src);", it shows the correct image names on mouseover and mouseout - I guess the problem is getting the "onload" method to assign the image src correctly...

Reply With Quote
  #7  
Old April 1st, 2008, 11:24 AM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
Click here for more information.
 
Join Date: Sep 2004
Location: Israel
Posts: 26,621 Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)  Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 4 Days 13 h 47 m 29 sec
Reputation Power: 1441
try adding src="pixel.gif" to both images and create image with such
name with minimal file size.

Reply With Quote
  #8  
Old April 1st, 2008, 11:38 AM
cjreynolds cjreynolds is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 351 cjreynolds User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 10 h 9 m 21 sec
Reputation Power: 4
Now it looks like:
Code:
<A HREF="http://www.ntsbdc.org/default.asp"><IMG ID="btnHome" SRC="images/pixel.gif" onload="this.src = btnHomeWhite.src;" BORDER="0" onMouseOver="this.src = btnHomeBlue.src;" onMouseOut="this.src = btnHomeWhite.src;"/></A>

and I get "stack overflow" when the page is loaded, on mouse over, and on mouse out - the correct button image is displayed at page load, but doesn't change on mouseover/mouseout.

Reply With Quote
  #9  
Old April 1st, 2008, 11:45 AM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
Click here for more information.
 
Join Date: Sep 2004
Location: Israel
Posts: 26,621 Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)  Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 4 Days 13 h 47 m 29 sec
Reputation Power: 1441
sorry, my bad - should have seen this coming.
change this to:
Code:
onload="if (!this.getAttribute('loaded')) {this.setAttribute('loaded', '1'); this.src = btnHomeWhite.src;}"

let me know how it goes!
Comments on this post
cjreynolds agrees: That's what it needed!

Reply With Quote
  #10  
Old April 1st, 2008, 12:22 PM
cjreynolds cjreynolds is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 351 cjreynolds User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 10 h 9 m 21 sec
Reputation Power: 4
That worked great - Thanks!

joe

Reply With Quote
  #11  
Old April 2nd, 2008, 02:41 AM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
Click here for more information.
 
Join Date: Sep 2004
Location: Israel
Posts: 26,621 Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)  Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 4 Days 13 h 47 m 29 sec
Reputation Power: 1441
Quote:
Originally Posted by cjreynolds
That worked great - Thanks!

joe
took us long enough.. cheers!

Reply With Quote
  #12  
Old May 9th, 2008, 10:25 AM
cjreynolds cjreynolds is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 351 cjreynolds User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 10 h 9 m 21 sec
Reputation Power: 4
Not sure if I can still use this thread, but here goes:

I incorporated the above changes, and it has worked great since then. However, when I run the page through the w3c markup validator (using HTML 4.01 transitional doctype), it won't allow an onload attribute on an image.

Is there a way around this?

joe

Reply With Quote
  #13  
Old May 9th, 2008, 12:32 PM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
Click here for more information.
 
Join Date: Sep 2004
Location: Israel
Posts: 26,621 Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)