...

View Full Version : &



BubikolRamios
12-21-2010, 01:52 AM
I'm changing href attributes with js into something like:

&p1=100&p2=10.....

when html walidator reads page with that, it does not like it.

How to handle that ?

Old Pedant
12-21-2010, 03:22 AM
Just what the validator tells you to do:

xxxx.php?foo=7&p1=100&p2=10

But the browsers aren't as fussy as the validator.

BubikolRamios
12-21-2010, 03:42 AM
Thanks. Looks like this will work.

rnd me
12-21-2010, 11:04 PM
I'm changing href attributes with js into something like:

&p1=100&p2=10.....

when html walidator reads page with that, it does not like it.

How to handle that ?

how does a validator see the result of javascript execution?
normally, you validate just the hard-coded html of a page.

Old Pedant
12-21-2010, 11:10 PM
When you code something like this:


<script type="text/javascript">
document.write('<a href="xyz.php?page=1&whack=me">do it</a>');
</script>

The validator will complain, technically correctly, about that &.

rnd me
12-21-2010, 11:43 PM
When you code something like this:


<script type="text/javascript">
document.write('<a href="xyz.php?page=1&whack=me">do it</a>');
</script>

The validator will complain, technically correctly, about that &.

inline javascript using XML reserved characters should wrap the program body in CDATA "comments", which will solve the validation issue without junking up the plain text javascript. hard-escaping the reserved chars could cause portability issues.

Old Pedant
12-22-2010, 12:00 AM
inline javascript using XML reserved characters should wrap the program body in CDATA "comments",

Agreed. But you asked.

BubikolRamios
12-22-2010, 06:30 PM
so, this is not resolved.
Validator does not complain if js generated link contains:

...?p100=12&amp;selection=1
but cant read selection parameter on server (after link click )then, unless it is :

?p100=12&selection=1

any suggestion ?

I guess CDATA, cant be used as it comes out as plain text from js.

DJCMBear
12-22-2010, 07:30 PM
Try using the //<![CDATA[ and //]]>.

For example.


<script type="text/javascript">
//<![CDATA[
document.write('<a href="xyz.php?page=1&whack=me">do it</a>');
//]]>
</script>

BubikolRamios
12-22-2010, 08:19 PM
Seems this will work & validate. Thanks.


result = result.replace("&","//<![CDATA[" + "&amp;" + "//]>");

DJCMBear
12-22-2010, 08:26 PM
Seems this will work. Thanks.


result = result.replace("&","//<![CDATA[" + "&amp;" + "//]>");


That isn't a good thing to do it makes more work for you and may slow down the codes as it will have to replace every & sign why not just do this.



<script type="text/javascript">
//<![CDATA[
// All your javascript codes here
//]>
</script>

BubikolRamios
12-22-2010, 09:18 PM
so basicaly, you are saying that ewery js file should have
<![CDATA[ at top and
and
//]>
at bottom ?

What if there is
xxx.innerHTML = "<...."
inside js
will that work ?

DJCMBear
12-22-2010, 09:22 PM
Not in a .js file no only use them comment tags when you put javascript codes on the page itself so only use them on the codes that if you view the source code you can see it, as the validator only obtains the files source code and checks it for errors and them comment tags say this is a comment but still runs the codes between them, if this makes sense to you.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum