Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

HTML Forum


You are currently viewing our HTML Forum as a guest. Please register to participate.
Login



Post a Project »

Find a Professional HTML Freelancer!

Find a Freelancer to help you with your HTML projects

FREE Outsourcing eBook!

Reply
Repeating code in cell not working?
Old 11-22-2007, 01:16 PM Repeating code in cell not working?
Novice Talker

Posts: 9
Trades: 0
Hi,

I coded this, so when you rollover, the cell background changes, rather than making 2 different menu images for each one. Saves time and bandwidth... but I tried to repeat the code in more than 1 cell and it's not working.

Here is my code (jscript and css in same file)

HTML Code:
<html> 
<head> 
<title>Change Test</title> 
<style type="text/css"> 
td.image { 
background: url(http://cjnet.info/images/bg/1.gif); 
} 
td.image2 { 
background: url(http://cjnet.info/images/bg/2.gif); 
}
a:link {
 color: #FFFFFF;
}
</style> 
<SCRIPT language="JavaScript">
<!--
if (document.images)
{
  pic1= new Image(100,25); 
  pic1.src="http://cjnet.info/images/bg/1.gif"; 
  pic2= new Image(240,55); 
  pic2.src="http://cjnet.info/images/bg/2.gif"; 
}
//-->
</SCRIPT>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head> 
<body> 
<table width="100" height="43"> 
<tr> 
<td height="37" id="changebg" name="changebg" background="http://cjnet.info/images/bg/1.gif" bgcolor="#009933"> 
<a href="#" onMouseOver="changebg.className='image2'" onMouseOut="changebg.className='image'">Change</a></td> 
</tr> 
</table> 
</body> 
</html>
and this is the page where it works (on 1 cell only);
http://cjnet.info/pages/projects/
cj-real is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-22-2007, 01:59 PM Re: Repeating code in cell not working?
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,380
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
You have a space in front of the classname in the event call and there can be only ONE element with any particular ID
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?

Last edited by chrishirst; 11-22-2007 at 02:00 PM..
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 11-22-2007, 02:22 PM Re: Repeating code in cell not working?
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Try to replace
HTML Code:
onMouseOver="changebg.className='image2'"
with
HTML Code:
onMouseOver="this.className='image2'"
This should remove the problem of conflicting id's, and you could even remove the name attribute.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 11-23-2007, 06:45 AM Re: Repeating code in cell not working?
Novice Talker

Posts: 9
Trades: 0
Quote:
Originally Posted by chrishirst View Post
You have a space in front of the classname in the event call and there can be only ONE element with any particular ID
so what do I do about it.

and changing the "changebg." to "this." does not work becuase it cannot run will the cell
cj-real is offline
Reply With Quote
View Public Profile
 
Old 11-23-2007, 07:09 AM Re: Repeating code in cell not working?
Novice Talker

Posts: 9
Trades: 0
Finished it, changed code to

HTML Code:
<html> 
<head> 
<title>Change Test</title> 
<style type="text/css"> 
td.image { 
background: url(http://cjnet.info/images/bg/1.gif); 
} 
td.image2 { 
background: url(http://cjnet.info/images/bg/2.gif); 
}
a:link {
 color: #FFFFFF;
}
</style> 
<SCRIPT language="JavaScript">
<!--
if (document.images)
{
  pic1= new Image(100,25); 
  pic1.src="http://cjnet.info/images/bg/1.gif"; 
  pic2= new Image(240,55); 
  pic2.src="http://cjnet.info/images/bg/2.gif"; 
}
//-->
</SCRIPT>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head> 
<body> 
<table width="100" height="43"> 
<tr> 
<td height="37" id="changebg" name="changebg" background="http://cjnet.info/images/bg/1.gif" bgcolor="#009933"> 
<a href="#" onMouseOver="changebg.className='image2'" onMouseOut="changebg.className='image'">Change</a></td> 
</tr> 
<tr> 
<td height="37" id="changebg1" name="changebg1" background="http://cjnet.info/images/bg/1.gif" bgcolor="#009933"> 
<a href="#" onMouseOver="changebg1.className='image2'" onMouseOut="changebg1.className='image'">Change</a></td> 
</tr> 
</table> 
</body> 
</html>
Elements now have different names and will do for each cell.
cj-real is offline
Reply With Quote
View Public Profile
 
Old 11-23-2007, 07:10 AM Re: Repeating code in cell not working?
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,380
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
HTML Code:
<html> 
<head> 
<title>Change Test</title> 
<style type="text/css"> 
td.image { 
background-image: url(images/1.gif);
 
} 
td.image2 { 
background-image: url(images/2.gif); 
}
a:link {
 color: #FFFFFF;
}
</style> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head> 
<body> 
<table width="100" height="43"> 
<tr> 
<td height="37" class="image" onMouseOver="this.className='image2'" onMouseOut="this.className='image'"> 
<a href="#" >Change</a></td> 
<td height="37" class="image" onMouseOver="this.className='image2'" onMouseOut="this.className='image'"> 
<a href="#" >Change</a></td> 
<td height="37" class="image" onMouseOver="this.className='image2'" onMouseOut="this.className='image'"> 
<a href="#" >Change</a></td> 
<td height="37" class="image" onMouseOver="this.className='image2'" onMouseOut="this.className='image'"> 
<a href="#" >Change</a></td> 
</tr> 
</table> 
</body> 
</html>
www.candsdesign.co.uk/demo/wt/cells/
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?

Last edited by chrishirst; 11-24-2007 at 02:54 AM.. Reason: changed code tags
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 11-23-2007, 09:18 AM Re: Repeating code in cell not working?
Novice Talker

Posts: 9
Trades: 0
......?
cj-real is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Repeating code in cell not working?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.44717 seconds with 12 queries