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:
  #1  
Old November 14th, 2004, 06:54 AM
trevorsaint trevorsaint is offline
Contributing User
ASP Free Novice (500 - 999 posts)
 
Join Date: Aug 2004
Posts: 592 trevorsaint User rank is Sergeant (500 - 2000 Reputation Level)trevorsaint User rank is Sergeant (500 - 2000 Reputation Level)trevorsaint User rank is Sergeant (500 - 2000 Reputation Level)trevorsaint User rank is Sergeant (500 - 2000 Reputation Level)trevorsaint User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 21 h 16 m 17 sec
Reputation Power: 10
javascript to change images and a style attribute on rollover?

Hi all, I am having a little problem with an effect I am after.

In connection with javascript and css.

Basically I have 5 links or options. And on hover of one of the links two images change, this is done using some javascript, however I also need a style background class to change on rollover and rollout. so when rollover, the images change and the class background style active is used, and on rollout the images revert and the class becomes inactive version.

Any advice?

cheers

Trev

Reply With Quote
  #2  
Old November 14th, 2004, 07:18 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,969 Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)  Folding Points: 342040 Folding Title: Super Ultimate Folder - Level 1Folding Points: 342040 Folding Title: Super Ultimate Folder - Level 1Folding Points: 342040 Folding Title: Super Ultimate Folder - Level 1Folding Points: 342040 Folding Title: Super Ultimate Folder - Level 1Folding Points: 342040 Folding Title: Super Ultimate Folder - Level 1Folding Points: 342040 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 5 Days 15 h 9 m 16 sec
Reputation Power: 1556
Code:
onmouseover="elementid.attributes['class'].value='active'; onmouseout=elementid.attributes['class'].value='inactive';

Reply With Quote
  #3  
Old November 14th, 2004, 08:16 AM
trevorsaint trevorsaint is offline
Contributing User
ASP Free Novice (500 - 999 posts)
 
Join Date: Aug 2004
Posts: 592 trevorsaint User rank is Sergeant (500 - 2000 Reputation Level)trevorsaint User rank is Sergeant (500 - 2000 Reputation Level)trevorsaint User rank is Sergeant (500 - 2000 Reputation Level)trevorsaint User rank is Sergeant (500 - 2000 Reputation Level)trevorsaint User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 21 h 16 m 17 sec
Reputation Power: 10
Hi sw, thx for the reply.

I did try this:

<a onmouseover="lightup('pic1','pic2')" onmouseout="turnoff('pic1','pic2')">

for the two images to change with javascript of course.

And this for the css style change:

<tr onmouseover="this.className='over'" onmouseout="this.className='out'" class="out">

It works, but only in IE.

I am guessing yours is a little better, how best to go about applying it, and is it workable with other browser types?

Thx for the reply again


Reply With Quote
  #4  
Old November 14th, 2004, 08:24 AM
trevorsaint trevorsaint is offline
Contributing User
ASP Free Novice (500 - 999 posts)
 
Join Date: Aug 2004
Posts: 592 trevorsaint User rank is Sergeant (500 - 2000 Reputation Level)trevorsaint User rank is Sergeant (500 - 2000 Reputation Level)trevorsaint User rank is Sergeant (500 - 2000 Reputation Level)trevorsaint User rank is Sergeant (500 - 2000 Reputation Level)trevorsaint User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 21 h 16 m 17 sec
Reputation Power: 10
I am having an issue applying your code, any ideas as below:


<a onmouseover="lightup('pic1','pic2')" onmouseout="turnoff('pic1','pic2')">
<table width="198" height="29" border="0" cellpadding="0" cellspacing="0">
<tr onmouseover="elementid.attributes['over'].value='active';" onmouseout="elementid.attributes['class'].value='out'" class="out">
<td width="28"><img src="images/search/search_bullet.gif" name="pic1" border="0" id="pic1"></td>
<td>Flight+Car+Hotel</td>
<td width="68"><img src="images/search/fhc-icons.gif" name="pic2" border="0" id="pic2"></td>
</tr>
</table>
</a>

cheers

Trev,

apparently elementid is undefined. do i need to apply an id to the tr or something along those lines??

help would be great

T

Reply With Quote
  #5  
Old November 14th, 2004, 08:31 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,969 Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)  Folding Points: 342040 Folding Title: Super Ultimate Folder - Level 1Folding Points: 342040 Folding Title: Super Ultimate Folder - Level 1Folding Points: 342040 Folding Title: Super Ultimate Folder - Level 1Folding Points: 342040 Folding Title: Super Ultimate Folder - Level 1Folding Points: 342040 Folding Title: Super Ultimate Folder - Level 1Folding Points: 342040 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 5 Days 15 h 9 m 16 sec
Reputation Power: 1556
the code simply changes the class of the span upon mouse over and mouse out. it wasn't cross browser (*shamed*) but here is cross browser version:
Code:
 <style>
 .class1 {color: blue;}
 .class2 {color: red;}
 </style>
 <span id="myspan1" class="class1">hello</span><br />
 <span id="myspan2" class="class2" onmouseover="document.getElementById('myspan1').attributes['class'].value = 'class2';" 
  onmouseout="document.getElementById('myspan1').attributes['class'].value = 'class1'">hello</span><br />
 


I tested it on IE and Firefox, I don't care for other browsers as they're too minor.
as you see, it's doing exactly what your (shorter) code is doing only for IE, but using more modular coding.

Reply With Quote
  #6  
Old November 14th, 2004, 08:33 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,969 Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)  Folding Points: 342040 Folding Title: Super Ultimate Folder - Level 1Folding Points: 342040 Folding Title: Super Ultimate Folder - Level 1Folding Points: 342040 Folding Title: Super Ultimate Folder - Level 1Folding Points: 342040 Folding Title: Super Ultimate Folder - Level 1Folding Points: 342040 Folding Title: Super Ultimate Folder - Level 1Folding Points: 342040 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 5 Days 15 h 9 m 16 sec
Reputation Power: 1556
Quote:
Originally Posted by trevorsaint
I am having an issue applying your code, any ideas as below:


<a onmouseover="lightup('pic1','pic2')" onmouseout="turnoff('pic1','pic2')">
<table width="198" height="29" border="0" cellpadding="0" cellspacing="0">
<tr onmouseover="elementid.attributes['over'].value='active';" onmouseout="elementid.attributes['class'].value='out'" class="out">
<td width="28"><img src="images/search/search_bullet.gif" name="pic1" border="0" id="pic1"></td>
<td>Flight+Car+Hotel</td>
<td width="68"><img src="images/search/fhc-icons.gif" name="pic2" border="0" id="pic2"></td>
</tr>
</table>
</a>

cheers

Trev,

apparently elementid is undefined. do i need to apply an id to the tr or something along those lines??

help would be great

T

"elementid" is only example... you have to replace it with the id of the control which you want its class to be changed, or in your case "this".

Reply With Quote
  #7  
Old November 14th, 2004, 08: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,969 Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)  Folding Points: 342040 Folding Title: Super Ultimate Folder - Level 1Folding Points: 342040 Folding Title: Super Ultimate Folder - Level 1Folding Points: 342040 Folding Title: Super Ultimate Folder - Level 1Folding Points: 342040 Folding Title: Super Ultimate Folder - Level 1Folding Points: 342040 Folding Title: Super Ultimate Folder - Level 1Folding Points: 342040 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 5 Days 15 h 9 m 16 sec
Reputation Power: 1556
in your case the code would be more simple:
<tr onmouseover="this.attributes['class'].value='active';" onmouseout="this.attributes['class'].value='out';" class="out">

Reply With Quote
  #8  
Old November 14th, 2004, 08:40 AM
trevorsaint trevorsaint is offline
Contributing User
ASP Free Novice (500 - 999 posts)
 
Join Date: Aug 2004
Posts: 592 trevorsaint User rank is Sergeant (500 - 2000 Reputation Level)trevorsaint User rank is Sergeant (500 - 2000 Reputation Level)trevorsaint User rank is Sergeant (500 - 2000 Reputation Level)trevorsaint User rank is Sergeant (500 - 2000 Reputation Level)trevorsaint User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 21 h 16 m 17 sec
Reputation Power: 10
Thumbs up Works a Treat

PERFECT

thankyou

Trev

Reply With Quote
  #9  
Old November 16th, 2004, 11:43 AM
sio2i sio2i is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 13 sio2i User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Red face

im having the same problem, but I am more html illiterate than most people around here, please forgive me. So to make my life and your life easier when someone tries to help... i have posted my link, so you can go in, and look at the source. PLEASEPLEASEPLEASE . thanks in advance!!!

I am trying to change two images when hovering over the exhibitions image:

http://www.columbia.edu/~xkm1/test.html

(when hovering over exhibitions, i want the exhibitions image to change as well as the picture in the middle.) as you can see, i got exhibitions, but not the other, I tried to apply the solution given by someone else, (and the empty code is in the bottom for reference is what I tried), but it didn't work. someone please HELP!!

Reply With Quote
  #10  
Old November 16th, 2004, 11:58 AM
robglobal robglobal is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Location: Atlanta
Posts: 86 robglobal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 44 m 10 sec
Reputation Power: 4
Send a message via AIM to robglobal
Cool

Use this function:

<script>

function swapBoth (img1, img1o,img2, img2o) {
if (document.images) {
document.images[img1].src=img1o;
document.images[img2].src=img2o;
}
}

</script>

for the first image, do this:

<img src="images/pic.gif" width="69" height="68" border ="0" name="pic1" id="pic1" onMouseOver ="swapBoth('pic1','images/pic_on.gif','img2','images/clear_on.gif')" onMouseOut ="swapBoth('pic1','images/pic.gif','img2','images/clear.gif')" >


For the second rollover, set up a blank image:

<img src="images/clear.gif" width="277" height="213" name ="img2" id="img2">

that should do it.

Reply With Quote
  #11  
Old November 16th, 2004, 01:45 PM
sio2i sio2i is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 13 sio2i User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
OMG! IT WORKED! yay! thanks

Reply With Quote
  #12  
Old November 16th, 2004, 01:46 PM
sio2i sio2i is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 13 sio2i User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
thanks thanks~~ thanks! did i say thanks? :-D

Reply With Quote
  #13  
Old November 17th, 2004, 11:01 AM
robglobal robglobal is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Location: Atlanta
Posts: 86 robglobal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 44 m 10 sec
Reputation Power: 4
Send a message via AIM to robglobal
Cool

You're quite welcome. Check out this site 4 supplemental info:


http://www.daxassist.com/js/disjointedrollovers.cfm

Reply With Quote