PDA

View Full Version : onload attribue generating W3C Validation error with XHTML Transitional 1.0 doctype



Marventus
14 May 2010, 11:35 AM
Hello, everyone!

I'm co-developing a WordPress blog (http://www.tebp.org), to which we have added a Frontpage Slideshow (FPSS) plugin to display featured posts.

Before adding this feature, the blog was validating beautifully on the W3C Validator in XHTML Transitional 1.0. However, after adding FPSS, we are getting a there is no attribute "onload" on Line 188:

<img id="fs-entry-img-1" class="fs-skip" alt=" " src="http://www.tebp.org/wp-content/themes/thesis_16/custom/images/posts/about2.jpg" onload="fsDoSlide()" />

According to the author of the plugin, and to other articles and threads I have read about this issue, the error should not be occurring in Transitional mode, but the Validator is still choking on it. The "HTML Tidy" proposed version (which removes the onload command) does not work because the images inside the FPSS stop sliding by default (you have to click on the buttons for the slideshow to start sliding the pics).

The slideshow is powered by jQuery and the whole layout of the FPSS is generated through php code, so here's the corresponding PHP code line just in case:

$fscontent .= '<img id="fs-entry-img-'.$id.'" class="fs-skip" alt=" " src="'.$entry['image'].'"';
if ($id == $fslast) $fscontent .= ' onload="fsDoSlide()"'; // put this to make another loop after the last image
$fscontent .= ' />';

Any help on this will be greatly appreciated. Many thanks!

Marventus
16 May 2010, 07:51 PM
I already figured this one out. The solution was suggested to me in a different forum. Basically, I just needed to wrap the JS script inside a <script> tag for it to work. Here's the code for those of you who land on this thread:

HTML:

<img id="fs-entry-img-1" class="fs-skip" alt="" src="http://www.tebp.org/wp-content/themes/thesis_16/custom/images/posts/about2.jpg"/>
<script type="text/javascript">
document.images[document.images.length-1].onload = fsDoSlide
</script>

PHP:

$fscontent .= ' />';
if ($id == $fslast) $fscontent .= ' <script type="text/javascript"> document.images[document.images.length-'.$id.'].onload = fsDoSlide </script>';
Hope this helps!