& in url in JS rendering as not valid by W3C's validator

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

& in url in JS rendering as not valid by W3C's validator

Post by anjanesh »

In a JS code embedded in an HTML page.

Code: Select all

document.getElementById(&quote;frm1&quote;).action = &quote;somepage.php?x=1&y=2&quote;;
W3C' validator is showing errors because of the & sign in the url.
1. Why is it trying to validate code in JS block ?
2. When I replace & with & it shows This Page Is Valid etc etc but obviously the url sent to is somepage.php?x=1&y=2 and not somepage.php?x=1&y=2.

How I rectify this ?
Thanks
Last edited by anjanesh on Fri Apr 01, 2005 1:28 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

that is correct usage in XHTML, at least.. The browser should parse it as you think it should.
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

But it doesnt seem to work with & - W3C is parsing it as valid though.
But when the form is submitted the url has & instead of &

Code: Select all

<script type=&quote;text/javascript&quote;>
function somefunction ()
 {
 	// determine what y's value is
 	document.getElementById(&quote;frm1&quote;).action = &quote;somepage.php?x=1&amp;y=&quote;+y;
 	document.getElementById(&quote;frm1&quote;).submit();
 }
</script>
y is not user-input - some value based on what the user does on the page
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Re: & in url in JS rendering as not valid by W3C's valid

Post by Roja »

anjanesh wrote: 1. Why is it trying to validating code in JS block ?
Boy: Do not try and bend the spoon. That's impossible. Instead only try to realize the truth.

Neo: What truth?

Boy: There is no spoon.

Neo: There is no spoon?

Boy: Then you'll see that it is not the spoon that bends, it is only yourself.

--
Solution: Move your js to a seperate file, as you should anyways, so it can be cached. Then there will be no spoon for the validator to try and bend.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Just a guess but correctly commenting out your code might help.

You should be doing this anyway.

Code: Select all

<script type=&quote;text/javascript&quote;>
<!-- Comment me out

// End -->
</script>
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Re: & in url in JS rendering as not valid by W3C's valid

Post by n00b Saibot »

<off-topic>
Roja wrote: Boy: Do not try and bend the spoon. That's impossible. Instead only try to realize the truth.

Neo: What truth?

Boy: There is no spoon.

Neo: There is no spoon?

Boy: Then you'll see that it is not the spoon that bends, it is only yourself.
You sure seem to be as impressed by The MATRIX as I am. Truly stumped :D
Post Reply