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
Old 09-21-2005, 07:41 PM Img name attribute?
webgrrl's Avatar
Skilled Talker

Posts: 74
Trades: 0
Hi, All -

I am using a Javascript function to swap photos onclick. Here is the img src:
<IMG id="PrimaryPhoto" name="PrimaryPhoto" onError="src='photos/viewhomenophoto.gif';" SRC="photos/<?=$photo1?>" WIDTH="330" ALIGN="middle" ALT="Click for Larger Photos" border="0" />
When I try to W3-validate the HTML, I get this error:
there is no attribute "ONERROR", there is no attribute "NAME"
Do I need a different DocType or something? My current DocType is:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

I tried using an XHTML doctype but it broke all my css tags.

Any advice?

Thanks in advance,
WebGrrl
webgrrl is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-22-2005, 02:12 AM
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
There is no onerror event. it doesn't exist in the DOM and because of that error, the name attribute also throws as an error.

The alt attribute should be used for text if the image is missing or fails to load, Other than that check for the image file existing server side and change the file name if it doesn't
__________________
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?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 09-22-2005, 05:00 PM
webgrrl's Avatar
Skilled Talker

Posts: 74
Trades: 0
Okay...I got rid of the onerror. (I checked for the image file existance with a php if statement instead.)

But I am still getting a there is no attribute "NAME" error when I try to validate the HTML.

What else can I try?

Thanks,
WebGrrl
webgrrl is offline
Reply With Quote
View Public Profile
 
Old 09-23-2005, 04:35 AM
Minaki's Avatar
Defies a Status

Posts: 1,626
Location: Guildford, UK
Trades: 0
Try just taking the name attribute out? You've got the id attribute in there.
__________________
Minaki Serinde MCP
"Wow, Linux is nearly on-par with Windows ME!"

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
Minaki is offline
Reply With Quote
View Public Profile Visit Minaki's homepage!
 
Old 09-23-2005, 02:54 PM
webgrrl's Avatar
Skilled Talker

Posts: 74
Trades: 0
I tried taking the name attribute out but then my javascript didn't work...
function switchPhoto(oObj)
{

var cPath = '';
cPath = oObj.src;

if (cPath == 'images/placeholder.gif') {
//do nothing
}
else {
//swap photo
document.PrimaryPhoto.src = oObj.src;
}

}
WebGrrl
webgrrl is offline
Reply With Quote
View Public Profile
 
Old 09-25-2005, 05:31 AM
Extreme Talker

Posts: 160
Trades: 0
You could reference the image by position in the images array so instead of

document.PrimaryPhoto.src = oObj.src;

try

document.images[index].src = oObj.src;

index would indicate the position of the image in the document. The first image would be referenced as 0, the third 2 and so on.
ElectricSheep is offline
Reply With Quote
View Public Profile
 
Old 09-25-2005, 08:57 AM
Minaki's Avatar
Defies a Status

Posts: 1,626
Location: Guildford, UK
Trades: 0
There has to be another way of doing it than that. I don't know a lot of JavaScript myself...
It just seems a very bad idea to reference images by their position in the document, cos this could easily change - and then you'd have to work out the new position and changethe code.
__________________
Minaki Serinde MCP
"Wow, Linux is nearly on-par with Windows ME!"

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
Minaki is offline
Reply With Quote
View Public Profile Visit Minaki's homepage!
 
Old 09-25-2005, 10:37 AM
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Code:
document.getElementById("PrimaryPhoto").src =
__________________
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?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 09-25-2005, 12:10 PM
Extreme Talker

Posts: 160
Trades: 0
This is the W3C way to do it but won't work in older / non-standard following browsers.

Referencing elements through number rather than name actually makes it very easy to loop through all images, forms, form elements, applets, scripts, stylesheets etc applying something to each as you do. This approach pre-dates W3C DOM so is ideal for wide audiences - even Netscape 4 will understand!

Anyway, you could use the name attribute validly with the following <!DOCTYPE> :

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/REC-html401/loose.dtd">
ElectricSheep is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Img name attribute?
 

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.33317 seconds with 12 queries