Welcome to WebmasterWorld Guest from 3.214.184.124
Forum Moderators: open
Ive recently been working on getting my site valid XHTML 1.0 Strict, and most of it is, except 2 parts, which is some javascript issues in the HTML header.
My javascript library of choice is jQuery. (just to point that out about the javascript commands lol)
heres problem #1:
Im using PHP to generate a 'where you are currently at, and how you got there' navigation based on how deep the viewer is in the site. once thats generated, i use javascript to write it out into a javascript generated area of the website. All of this javascript generating/writing is done in the <head> section. the problem is that the validator is seeing the <a></a> tags and throwing an error, even though its not actually being written in the head. how can i get this to validate?
Example:
PHP:$linkURL = 'http://www.example.com/index.php';
$linkArea = '?area='.$Area;
$linkLevel1 = '&level1='.$Level1;
$linkLevel2 = '&level2='.$Level2;
$linkLevel3 = '&level3='.$Level3;
$linkLevel4 = '&level4='.$Level4;
$navHome = '<a href="'.$linkURL.'">Home</a>';
$navArea = '<a href="'.$linkURL.$linkArea.'">'.$Area.'</a>';
$navLevel1 = '<a href="'.$linkURL.$linkArea.'&sub=1'.$linkLevel1.'">'.$Level1.'</a>';
$navLevel2 = '<a href="'.$linkURL.$linkArea.'&sub=2'.$linkLevel1.$linkLevel2.'">'.$Level2.'</a>';
$navLevel3 = '<a href="'.$linkURL.$linkArea.'&sub=3'.$linkLevel1.$linkLevel2.$linkLevel3.'">'.$Level3.'</a>';
$navLevel4 = '<a href="'.$linkURL.$linkArea.'&sub=4'.$linkLevel1.$linkLevel2.$linkLevel3.$linkLevel4.'">'.$Level4.'</a>';
$navDivider = ' >> ';
$NAVDONE = '';
if ($Sub >= '0' ¦¦ !isset($Sub) ¦¦ $Sub == '') {
$NAVDONE .= $navHome.$navDivider.$navArea;
}
if ($Sub >= '1') {
$NAVDONE .= $navDivider.$navLevel1;
}
if ($Sub >= '2') {
$NAVDONE .= $navDivider.$navLevel2;
}
if ($Sub >= '3') {
$NAVDONE .= $navDivider.$navLevel3;
}
if ($Sub >= '4') {
$NAVDONE .= $navDivider.$navLevel4;
}
if ($Area == 'Home' ¦¦ $Area == '' ¦¦ !isset($Area)) {
$NAVDONE = $navHome;
}
Javascript:
jQuery(document).ready(function() {
jQuery('a[rel*=facebox]').facebox()
$('#facebox .navHeader').append('<?PHP echo $NAVDONE; ?>')
})
It complains about the <a></a> tags in the header.
problem #2:
jQuery.facebox(function($) {
jQuery.get('<?PHP echo 'example.php?area='.urlencode($_REQUEST['area']).'&sub='.urlencode($_REQUEST['sub']).'\&level1='.urlencode($_REQUEST['level1']).'\&level2='.urlencode($_REQUEST['level2']).'\&level3='.urlencode($_REQUEST['level3']).'\&level4='.urlencode($_REQUEST['level4']);?>', function(data) { jQuery.facebox(data) })
})The PHP in this snippet just adds the correct variables to the url. My problem is the ampersands ("&").
I cant just use "&" because Im feeding it to the browser using jQuery.get, then sending the data to another javascript generated area of the page. Help?
[edit] removed personal links
2. Regardless, you should still be escaping the ampersand as &. jQuery should be able to take a string like "example.php?area=x&sub=y". If it can't, then I would call that a pretty big jQuery bug.
Hope that helps.
It isnt converting the & to &
For the first, i used PHP's function 'htmlentities' to encode the html characters, then sent them to the external script, then decoded them using another javascript function, 'html_entity_decode' (check out the php.js project). after having successfully (and validly) got the url from the main page to the external script, i then launched the function i had been previously using.
for the second, i sent the specific variables via another javascript function, then put the url together in the external file, then sent it to the browser using jQuery.get();
(I really didn't want to do this, it was just more work than id hoped for. im not too big on JS, but its necessary lol)