XHTML Validation

Alex

Diamond Member
Oct 26, 1999
6,995
0
0
i'm kinda stuck here, i'd like to get a website i made validated to W3 standards and i've spent all day cleaning up code and optimizing stuff here and there but i still get tons of errors for using & and <> in my javascript

as far as i know it's ok to use thse characters as javascript operators and in fact it won't work if i use the HTML-safe equivalents <, &, etc

can anyone throw me a bone on this one?

link

thanks!

btw - i thought of saving all the javascript on my main page in an external file and link it, will that change anything? it'd be nice to say it's 100% compliant :)

edit: as you can see the javascript in question are Adobe's Rollover Image Functions from Dreamweaver, all the js i wrote by hand actually validates fine.
 

skrilla

Senior member
Oct 22, 2004
833
0
71
Actually... the above didn't validate:

You could use...

<script type="text/javascript">
<!--//--><![CDATA[//><!--

//Script...

//--><!]]>
</script>

In your case... The below seems to validate:



<script type="text/javascript">
<!--//--><![CDATA[//><!--
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a)&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a.indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a;}}
}

function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers.document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//--><!]]>
 

Alex

Diamond Member
Oct 26, 1999
6,995
0
0
thanks!

i just got home from work but i'll try it out tomorrow! :beer:
 

fs5

Lifer
Jun 10, 2000
11,774
1
0
or you could totally ignore validation and just go with what works. IMO getting to 100% w3c validation is more trouble than it's worth.
 

Alex

Diamond Member
Oct 26, 1999
6,995
0
0
Originally posted by: fs5
or you could totally ignore validation and just go with what works. IMO getting to 100% w3c validation is more trouble than it's worth.

you've got a great point but it's really not that much extra work... all I did was copy and paste the javascript to an external file and link to it, now I can say that my site is 100% W3C Validated.

it's stupid, i agree! but it's always a plus to be able to say something you created is 100% standards compliant...
 

Rip the Jacker

Diamond Member
Dec 29, 2004
5,415
1
76
Originally posted by: fs5
or you could totally ignore validation and just go with what works. IMO getting to 100% w3c validation is more trouble than it's worth.

You shouldn't totally ignore validation. If you're a novice coder (hell, even a pro) you might have forgotten an end tag, or something that would cause the layout to be thrown off in some lesser standards compliant browsers (assuming most of you develop on FF2 / Opera 9 / Safari 3). If you want to ignore validation, go ahead. I wasn't around in the early 00s on the web, but did that work out well when people didn't really care all that much about validation?

For those of you who thinks it takes too damn long, get the web developer extension and if you already have it, CTRL SHIFT A and just make sure there aren't any serious errors such as end tags. Most of the time you will forget to make your &'s as &'s, forget an alt attribute value on an image, etc.

Getting to 100% validation isn't that hard, assuming the user is using an XHTML Transitional Doctype where he can use deprecated elements such as <b>, <i>, or any of the HTML 4 doctypes. I see absolutely no point in using XHTML Strict or even XHTML 1.1 .. hell even XHTML Transitional if you're not using the right mime type for XHTML which is application/xhtml+xml and (here's my wild guestimate) 95% of "XHTML" pages are sent as text/html which means if they have errors, the pages still show up (where the real XHTML behavior when using the RIGHT doctype should be a notice on where in your document the error is, if there is any).

I see no point in using XHTML anymore, because people code webpages, and in any real large interactive website (maybe a blog?) where a user can enter HTML in comments, or maybe a forum... or something such as MySpace where the user gets to edit the HTML (do they even allow that btw? Lol) the page will *NEVER* be 100% valid and if the author used the right MIME type for XHTML then the pages wouldn't not display (if there were any errors) and IE doesn't even support XHTML.

I think the new trend (well, at least to real front end nerds that hang out in IRC, etc) is to go back to using HTML 4 Strict (which is pretty much the same as XHTML Transitional) except you have to exercise your fingers into not typing those extra /> tags, and you're actually using the RIGHT doctype.

Here's a link if anyone's interested -->
http://www.webdevout.net/articles/beware-of-xhtml

I code all my new sites in HTML 4 Strict, and try to get them to be as valid as they can be so that I know I have coded everything nicely, and valid. Of course validation does not in anyway mean that your layout will look the same cross-browser, nor does it mean your code is semantic, well structured, maintainable, and all that.
 

fs5

Lifer
Jun 10, 2000
11,774
1
0
I think we maybe talking about 2 different things. I'm talking w3c valid... as in see here:
http://validator.w3.org/

lets see,
yahoo.com, google.com, ubuntu.org, youtube.com... all didn't validate.
 

Rip the Jacker

Diamond Member
Dec 29, 2004
5,415
1
76
Originally posted by: fs5
I think we maybe talking about 2 different things. I'm talking w3c valid... as in see here:
http://validator.w3.org/

lets see,
yahoo.com, google.com, ubuntu.org, youtube.com... all didn't validate.

Yup. That's what I'm talking about. If you wanted to save time, you could CTRL SHIFT A with the webdev plugin on FF2. Of course you can't expect the most popular sites to be valid, great example would be google who refuse to go the standards way and instead rely on ancient, old code because they think it's more cross-browser compatible since browsers don't even fully support CSS1 / CSS 2 so they go the table way.

Check out these articles

http://www.456bereastreet.com/...and_use_web_standards/
http://www.456bereastreet.com/...le_meet_web_standards/
http://www.456bereastreet.com/...ogle_valid_and_strict/
http://www.joesapt.net/2006/07/24/12.15.00/
 

Rip the Jacker

Diamond Member
Dec 29, 2004
5,415
1
76
Ubuntu(.com) is a great example of XHTML being mis-used. The author, whoever it was, wanted to be "strict" and "standard"-ish so he used an XHTML Strict doctype. Assuming the original author only did the homepage + interior or main templates, he probably isn't doing the updates on the homepage. Someone using a CMS is updating the homepage and they don't know as much HTML as the original author, where he intended to make this all strict XHTML, but the user forgot the alt attribute for the image and forgot an end tag, and if the real mime type for XHTML would have been used the homepage would have an error on it. That's why I'm against XHTML and am for HTML 4 + HTML 5.
 

Rip the Jacker

Diamond Member
Dec 29, 2004
5,415
1
76
Originally posted by: fs5
or you could totally ignore validation and just go with what works. IMO getting to 100% w3c validation is more trouble than it's worth.

I'd really love to see some of your code and see how you ignore validation.

Would you care to link me?
 

fs5

Lifer
Jun 10, 2000
11,774
1
0
Originally posted by: Rip the JackerOf course you can't expect the most popular sites to be valid,
why not? why wouldn't you follow in the footsteps of giants?
 

Alex

Diamond Member
Oct 26, 1999
6,995
0
0
i guess the one thing we can learn from this is that it doesn't really matter if it's 100% validated as long as it works well... with the website i was doing i ended up having to do a bit more work to make it valid and for what? it looks exactly the same and behaves exactly the same... that being said, validation is a good way to make sure you dot all your 'I's and cross all your 'T's
 

xtknight

Elite Member
Oct 15, 2004
12,974
0
71
Yeah, I also think (XHTML) validation is pointless when the code validates and it doesn't even work correctly in all the browsers. Why am I conforming to a standard that's apparently not even a standard? It is a pain, and it gains you absolutely nothing except a little icon from the w3c! You can still practice good programming practices using the standard HTML 4.01..standards.
 

Rip the Jacker

Diamond Member
Dec 29, 2004
5,415
1
76
Originally posted by: xtknight
Yeah, I also think (XHTML) validation is pointless when the code validates and it doesn't even work correctly in all the browsers. Why am I conforming to a standard that's apparently not even a standard? It is a pain, and it gains you absolutely nothing except a little icon from the w3c! You can still practice good programming practices using the standard HTML 4.01..standards.

Who says you need to waste more bandwidth by adding that retarded W3 icon on your site? Only novices start adding that crap to their sites.
 

Alex

Diamond Member
Oct 26, 1999
6,995
0
0
Originally posted by: Rip the Jacker
Originally posted by: xtknight
Yeah, I also think (XHTML) validation is pointless when the code validates and it doesn't even work correctly in all the browsers. Why am I conforming to a standard that's apparently not even a standard? It is a pain, and it gains you absolutely nothing except a little icon from the w3c! You can still practice good programming practices using the standard HTML 4.01..standards.

Who says you need to waste more bandwidth by adding that retarded W3 icon on your site? Only novices start adding that crap to their sites.

QFT. i think it's stupid to add all those validation banners... man i remember back in the day i always had a 'made with notepad' banner even though i used frontpage :p
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
Originally posted by: alex
i guess the one thing we can learn from this is that it doesn't really matter if it's 100% validated as long as it works well...
That's a very tempting but ultimately dangerous position because 'works well' is a very foggy term. Sure, it works well for the two or three browsers you tried, on the platform you happen to use, with the specific (soon-to-be-outdated) software versions you have available. The quirks and error handling you take for granted are not by any means guaranteed to exist outside of your small test environment.

Rip makes a very good point and that is that if you don't want to be pedantic, you shouldn't use xhtml. Html has always had a slightly fuzzy definition where a certain number of errors are expected by xhtml (being xml) does not. If modern browsers ever start treating xhtml like xml (which they should) they have every right to reject an entire document because of one & error in your javascript. Sounds scary, but many more cool things will be possible with that safety blanket of correctness.

You could argue that that will just never happen because web developers will never settle down and comply with standards. Keep in mind though, that things are vastly better than they were a few years ago and that is because people decided to do it the hard way and pay attention to standards. The process is not yet finished and I think in the future we can expect better support for compliance.

The profusion of browsers that we've seen since IE beat Netscape is very obviously a good thing for everybody (except microsoft I think). Imagine how much easier it would be to whip up a new and innovative browser if you could only worry about handling standards compliant documents. I'm sure it's orders of magnitude simpler than trying to handle the years of trash people produced just because it worked in the browser their boss said they had to support.

One point about the googles and yahoos of the world and their non-compliance. No, it's not a good example to set, but they can get away with it because they employ full time web developers by the hundreds or thousands and are constantly overhauling their code. When the next round of interesting clients evolves (be it a desktop browser or a mobile device or screen reader for the blind...) they will just fix whatever is broken and the old content will just disappear. Most websites do not have that luxury. Your code will stay around far longer than theirs and it will mess up clients that try to support standards.

Now, with that rant out of the way, I'd better go and tweak my code. Either to remove the last few xhtml inconsistencies or to change the doctype... :eek:
 

esun

Platinum Member
Nov 12, 2001
2,214
0
0
kamper, I'd argue that the current browser market is what's making standards useless. What does it matter if I code to XHTML strict if Firefox and IE6 still show enormous differences in the result? I still end up having to special case everything. Then when IE7 came out I found I had to change things again anyway. Perhaps someday, when 99% of the market is had by browsers that meet W3C standards, then coding to them will be worthwhile. Until then, it doesn't add anything.
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
Well, first of all, the world isn't ready for xhtml yet. The only way any browser will use it properly is if you have perfectly validating code and you do some magic with the Content-Type: header from your server.

As for standards in general, don't think of it as improving your pages today, think of it as not wrecking your pages tomorrow when the standards are actually supported. If you're not going to validate today, please please don't use xhtml. At least fall back to html4 (and I hear html5 is coming).