Forum Moderators: open

Message Too Old, No Replies

Embedded javascript messing HTML Validation

Ampersand in String

         

itledi

12:07 pm on Jan 5, 2008 (gmt 0)

10+ Year Member



My embedded javascript is messing up my HTML Validation.

I have a line which includes ampersands ("&score=") as a part of an url string, but W3 views it as a special non-existing character.

How can I resolve this issue?

var src="update.php?id="+id+"&score="+score;

Thanks

pageoneresults

12:14 pm on Jan 5, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You'll need to escape the ampersand...

&score

itledi

12:27 pm on Jan 5, 2008 (gmt 0)

10+ Year Member



Thank you,

So if I change this:

var src="update.php?id="+id+"&score="+score;

to this:
var src="update.php?id="+id+"&score="+score;

The html will be valid, but the script won't have any issues?

pageoneresults

2:50 pm on Jan 5, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The html will be valid, but the script won't have any issues?

Yes. Certain characters need to be escaped and the ampersand is one of them.

This...

&

Changes to...

&

All you are doing is adding the

amp;
to the
&

:)