W3C validation errors

phonydream2 - September 5, 2008 - 13:04
Project:Nodecarousel
Version:5.x-1.x-dev
Component:Miscellaneous
Category:support request
Priority:normal
Assigned:jcfiala
Status:active
Description

The code generated by this module is causing around eight errors for me when I try to validate my site on http://validator.w3.org/

I notice similar errors are appearing on popsci.com due to this modules output. Funnily enough, I didn't think the w3c validator was supposed to check ajax script, but it appears to be - here's a sample error from my site:

# Error Line 61, Column 25: document type does not allow element "div" here.

    buttonNextHTML: '<div><span>&gt;</span></div>',

The element named above was found in a context where it is not allowed. This could mean that you have incorrectly nested elements -- such as a "style" element in the "body" section instead of inside "head" -- or two elements that overlap (which is not allowed).

One common cause for this error is the use of XHTML syntax in HTML documents. Due to HTML's rules of implicitly closed elements, this error can create cascading effects. For instance, using XHTML's "self-closing" tags for "meta" and "link" in the "head" section of a HTML document may cause the parser to infer the end of the "head" section and the beginning of the "body" section (where "link" and "meta" are not allowed; hence the reported error).

#1

nrasmus - September 24, 2008 - 14:17

subscribing

#2

Damjan Dvorsek - October 2, 2008 - 09:02
Version:5.x-1.0» 5.x-1.x-dev

I'm also interested in a solution for this issue

#3

jcfiala - October 2, 2008 - 20:08

I'm not quite sure what can be done if the validator is complaining about text that contains html inside of javascript.

I mean, you could change it to buttonNextHTML: '<di'+'v><sp'+'an>&gt;</sp'+'an></d'+'iv>', but really, that's just a little rediculous, isn't it?

#4

jpappe - November 5, 2008 - 10:19

The way to fix this is to make sure that all inline javascript is contained in "CDATA" tags. Specifically, line 1076 in _nodecarousel_write_block() should be changed from

<?php
drupal_add_js
( get_jcarousel_initialization_block($nc), 'inline');
?>

to

<?php
drupal_add_js
("/* <![CDATA[ */\n" . get_jcarousel_initialization_block($nc) . "\n/* ]]> */", 'inline');
?>

After I made this change, I no longer got validation errors.

#5

jcfiala - November 5, 2008 - 15:24
Assigned to:Anonymous» jcfiala

Well, I still think it's deeply ridiculous that the validator cares about tags inside of javascript, but if it's that simple for me to get the validator to be happy, I think I'll do it on my next chance of making changes to the module.

Thanks for giving me the info on how to fix the problem.

#6

ugerhard - November 14, 2008 - 10:58

Another simple fix is to enclose the inline JavaScript output in HTML comment markup, for example like this (from theme_nodecarousel()):

<?php
  $content
.= '<script type="text/javascript">
  <!--
  var ul = document.getElementById("nc_'
. $nc->name .'"); ul.className+=" hidden";
  // -->
  </script>'
;
?>

 
 

Drupal is a registered trademark of Dries Buytaert.