views:

17

answers:

1

Hi, there is a script in my html tag

<script type="text/javascript">
 function setTaxDisplay(display)
 {
  window.location.href += (window.location.href.indexOf('?') > -1 ? '&' : '?') + 'taxInclude=' + display;
 }
</script>

When passed to validation It returns that the ampersand there isn't valid, but it's absolutely vital to the function of the page, is there a way I can make the validator ignore this? I don't need to validate the page, I'm no JS expert at all I'm not sure if I can replace it with &amp;.

Thanks.

+1  A: 

You are probably writing XHTML and serving it as text/html. Welcome to the joys of pretending one markup language is really another one.

You can wrap the script with commented out CDATA markers, but you should move it to an external file.

See http://www.w3.org/TR/xhtml-media-types/#C_4 for details and examples.

Alternatively — just write HTML. XHTML doesn't give benefits to most authors (and since your problem is with validation rather then with any of the tools you are using, you probably aren't one of the authors who does benefit from using XHTML)

David Dorward
I think I'll go with wrapping it, this isn't my site and I've just started working on it, so for now I'll wrap it and when I know I can safely swap it to HTML, I shall. Thanks :)
Kyle Sevenoaks