Current location: Hot Scripts Forums » General Web Coding » JavaScript » Firefox and W3C dont like name function in xhtml


Firefox and W3C dont like name function in xhtml

Reply
  #1 (permalink)  
Old 02-09-10, 05:32 AM
Frogger Frogger is offline
Wannabe Coder
 
Join Date: Jul 2006
Posts: 149
Thanks: 5
Thanked 0 Times in 0 Posts
Firefox and W3C dont like name function in xhtml

Hi,

I am using some javascript for mouseover in xhtml but FF and W3C dont like the name function in the code.

Is there anyway around this?

Code:
<script language="javascript" type="text/javascript">
if (document.images) {
image1 = new Image
image2 = new Image
 
image1.src = "pic1.jpg"
image2.src = "pic2.jpg"

 }
</script>

<a href="" onmouseover="document.pic.src=image2.src" onmouseout="document.pic.src=image1.src" >Picture</a>
						
<a href="" onmouseover="document.pic.src=image2.src" onmouseout="document.pic.src=image1.src"><img src="pic1.jpg" name="pic"  /></a>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 02-09-10, 07:41 AM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,516
Thanks: 20
Thanked 109 Times in 106 Posts
Use the id attribute on the img tag, then use document.getElementById('id').src to change the src.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 02-09-10, 12:00 PM
Frogger Frogger is offline
Wannabe Coder
 
Join Date: Jul 2006
Posts: 149
Thanks: 5
Thanked 0 Times in 0 Posts
Thanks for your help wirehopper. The below script worked a treat. Thanks very much again.

Code:
<a href="" onmouseover="document.getElementById('pic').src=image2.src" onmouseout="document.getElementById('pic').src=image1.src"><img src="pic1.jpg" id="pic"  /></a>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 02-09-10, 05:01 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,516
Thanks: 20
Thanked 109 Times in 106 Posts
If this gets too verbose, you can use:

Code:
var p=document.getElementById('pic');

/* and then refer to it as */

p.src='newvalue';
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 02-09-10, 05:13 PM
Frogger Frogger is offline
Wannabe Coder
 
Join Date: Jul 2006
Posts: 149
Thanks: 5
Thanked 0 Times in 0 Posts
Thanks again wirehopper. That too is good advice. Thanks again.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
W3c txt3rob HTML/XHTML/XML 1 01-09-07 06:45 PM


All times are GMT -5. The time now is 10:52 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.