Forum Moderators: open

Message Too Old, No Replies

Javascript in XHTML 1.1

         

Asia_Expat

9:44 pm on Apr 9, 2006 (gmt 0)

10+ Year Member



Please help me. I'm going mad. I can't get this to validate in an XHTML document...

<SCRIPT language='javascript' type='text/JavaScript src='http://cache.meta4-group.com/asiaexpat/spods.js?locale=en_US'></SCRIPT>
<SCRIPT language='javascript'>
//<![CDATA[
for (var i = 0, n = wfSPODArray.length; i < n; i++) {
var spod = wfSPODArray[i];
spodHtml = '<a href=' + spod.link + ' target=_blank><img src=' + spod.photo.url + ' width=120' +' height=120 border=0' + '></a><br/>' + '<a href=' + spod.link + ' target=_blank>' + spod.nickname + '</a>' + '<br/>' + spod.quote + '<br/>'
document.write(spodHtml);
}
//]]>
</SCRIPT>

DrDoc

11:57 pm on Apr 9, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



a) lowercase your tags
b) remove the language attribute as it is not valid
c) ensure that the type attribute is added to both
d) use double quotes

All this is readily available (and easily found) in the XHTML documentation, as well as in the validation results.

I mean no offense ... but, you need to read the XHTML documentation again. It will do you good and simplify your coding. :)

Asia_Expat

12:08 am on Apr 10, 2006 (gmt 0)

10+ Year Member



Oh wow! That green validation screen is so sweet.

Cheers buddy. I don't know how I missed those points really. I guess I'm tired.

JAB Creations

11:09 am on Apr 10, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can't use document.write when serving a page as application/xhtml+xml.

By default pages are served with a text/html mime. This is a valid option according to W3C standards for all doctypes up to XHTML 1.0 Strict. XHTML 1.1 however must be served as application/xhtml+xml. If you were using your own doctype (without any HTML/XHTML) you would use application/xml mime.

This is what I use instead currently but I personally need to learn how to use this a little better myself...

var l=document.createElementNS("http://www.w3.org/1999/xhtml","link");
l.setAttribute("href", "style.css");
l.setAttribute("media", "screen");
l.setAttribute("rel", "stylesheet");
l.setAttribute("title", "city");
l.setAttribute("type", "text/css");
document.getElementsByTagName("head")[0].appendChild(l);

John