Credit Cards - Find jobs - Free All Ebook PDF Download - Wordpress Theme - Debt Consolidation

PDA

View Full Version : javascript w3 strict xhtml validation (how to)


boobird
Feb 16th 2009, 4:45 pm
I am wondering if you can help me with a problem for javascript xhtml strict validation.

There is a protocol when using strict XHTML that all javascript should be
removed from the XHTML, and while we have done this for the majority of
elements, almost every form the site has requires javascript inline.

As an example, javascript uses the "&" character a lot, where as XML requires this to be "&", which we can not use in javascript.

Any suggestions?

1) We can keep the site as Strict XHTML and validate everything BUT the
javascript components, but this will result in lots of validation errors if
tested.

2) We can validate only for XHTML transitional. This would allow for 100%
validation.

joebert
Feb 16th 2009, 10:08 pm
You need to get rid of your inline usage of javascript and attach event listeners in an Init style loaded event handler.

I switched to transitional and saved myself a ton of headaches in general, not just with JS.

gnp
Feb 18th 2009, 8:58 am
If with inline you mean directly on the form elements or the form tag then no .. only the suggestion by joebert will do..

if how ever you mean that you have to define <script> tags in your source with the custom functions for each form then besides external files you could consider the CDATA section ..

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

alert('test & test');
// this will validate because it is contained in the CDATA section and the parser ignores it ;)
//]]>-->
</script>

but from your post i do not think that will do... had to post it though :)