Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old April 1st, 2005, 05:34 AM
Authorized User
Join Date: Jul 2004
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default problem with document.location and w3c


I have a problem with an XHTML page, with regards to validation according to w3c.

The problem is that my javascript function tries to call:

document.location = "?process=1&sort=name&latest=true"

Which works fine, but according to w3c, the ampersand characters need to be encoded as & i.e.:

document.location = "?process=1&sort=name&latest=true"

However, this doesn't work, since the browser does not unencode html entities in a javascript block!

arg! Apart from sticking the javascript file in a separate .js file so that w3c don't validate the contents, how can I get around this?

Old April 1st, 2005, 05:54 AM
joefawcett's Avatar
Wrox Author
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts

As far as I know they don't need to be encoded in script blocks, only in href and src attributes.


Joe (Microsoft MVP - XML)
Old May 3rd, 2005, 07:41 PM
nzakas's Avatar
Wrox Author
Join Date: Dec 2004
Posts: 217
Thanks: 0
Thanked 5 Times in 5 Posts

Joe is right, you don't need to escape your strings in JavaScript. If you are going for 100% valid XHTML, you should put your JavaScript code into an external JavaScript file and remove the encoding. The other option, depending on what browsers you're targeting, is to surround your JavaScript code with a CDATA section, such as:

<script type="text/javascript"><![CDATA[
    //your javascript code here
Be aware that this will cause an error in any browser that doesn't fully support XHTML (like IE).

Nicholas C. Zakas
Author, Professional JavaScript for Web Developers (ISBN 0764579088)

Similar Threads
Thread Thread Starter Forum Replies Last Post
textbox location problem evarol Reporting Services 0 August 23rd, 2006 02:37 AM
curious problem with W3C validator spineynorman HTML Code Clinic 1 April 3rd, 2006 08:20 PM
document.location.href surendran Javascript 5 August 3rd, 2005 10:17 PM
Append child problem org.w3c.dom vs_shankar2000 XML 0 December 8th, 2004 07:34 AM
Problem when changing the Location property armandoa Crystal Reports 0 October 8th, 2004 06:21 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.