Sheryl Tan

Navigation

Skip navigation.

Search

Site navigation

Email conversation

FromSheryl Tan
ToMe
SubjectProblem Implementing Nested List Collapsing Script in PHP
Date13 August 2005 23:45
Hi Mark!

Thanks so much for your script =) It's exactly what
I'm looking for. But I'm having some trouble
implementing it in my php script. I've successfully
worked it into just a plain html file
([URL]), but I'm
having trouble getting it to work once I embed it in
my php script
([URL]). This is
how I've done it:

echo "
<script type=text/javascript language=javascript1.2
src=listCollapse.js></script>\n
<script type=text/javascript language=javascript1.2>
<!--
function doOnLoad() {
  compactMenu('archive',false,'&plusmn; ');
  selfLink('archive','samePage',false);
}
//--></script>
</head>
<body background='images/background_g_06.gif'
marginheight='0' topmargin='0' vspace='0'
marginwidth='0' leftmargin='0' hspace='0'
onload='doOnLoad();'>";

and I've also done it this way:

?>
<script type=text/javascript language=javascript1.2
src=listCollapse.js></script>
<script type=text/javascript language=javascript1.2>
<!--
function doOnLoad() {
  compactMenu('archive',false,'&plusmn; ');
  selfLink('archive','samePage',false);
}
//--></script>

</head><body background='images/background_g_06.gif'
marginheight='0' topmargin='0' vspace='0'
marginwidth='0' leftmargin='0' hspace='0'
onload='doOnLoad();'>

<?

I've also tried different variations: using double
quotes, single quotes, no quotes, the script all on
one line, everything on its own line, etc.

But I still get the same error!
 
ERROR IN INTERNET EXPLORER
Error: 'childNodes.0.tagName' is null or not an object

ERROR IN OPERA
Event thread: load
Error:
name: TypeError
message: Statement on line 24: Could not convert
undefined or null to object
Backtrace:
  Line 24 of linked script
[URL]/listCollapse.js
    while (! y[x].childNodes[0].tagName ||
y[x].childNodes[0].tagName.toUpperCase() != oT &&
y[x].childNodes[0].tagName.toUpperCase() != "A")
                      Line 5 of linked script
[URL]/listCollapse.js
    compactChildren(baseElement, 0, oID, oAutoCol,
oPlMn, baseElement.tagName.toUpperCase(), oMinimalLink
&& oPlMn);
  Line 3 of inline#1 script in
[URL]
    compactMenu("archive", false, "&plusmn; ");
  Line 1 of  script 
    doOnLoad();
  At unknown location
    [statement source code not available]
(line 24 is the body tag)

I'm not sure if you've ever encountered this problem.
Is it just a problem with how I've embedded it in PHP?
I've tried googling, but haven't found anything
helpful with this problem. If you could help, I'd
really appreciate it =) Thanks in advance for any help
you can give!

Sheryl
FromMe
ToSheryl Tan
SubjectRe: Problem Implementing Nested List Collapsing Script in PHP
Date14 August 2005 13:34
Sheryl,

Thanks for the Opera error report, it's much more helpful than the IE one :)

OK, I think I see your problem. Your lists are using invalid HTML:
<ul id='archive'>
    <span class='nav' title=''>
        <li>2003
            <ul>
                <li><a href=...>03 2003</a></li>
                <li><a href=...>04 2003</a></li>

The span element is not allowed there. Only LI elements are allowed to be
immediate children of a UL or OL element. That is confusing the script
because it expects your lists to be valid.

The HTML specification:
http://www.w3.org/TR/html4/struct/lists.html#h-10.2
shows this:
<!ELEMENT UL - - (LI)+                 -- unordered list -->
The (LI)+ means that you may have only LI elements immediately inside UL
elements, and you must have at least one LI inside the UL.

> [URL]

I tried this page, but I cannot see the error on it. If removing the span
does not fix the problem, can you set up a demo page for me so I can see the
script fail?

Hope this helps

Mark 'Tarquin' Wilton-Jones - author of http://www.howtocreate.co.uk/
FromSheryl Tan
ToMe
SubjectRe: Problem Implementing Nested List Collapsing Script in PHP
Date15 August 2005 02:55
doh!!

thanks Mark!! =) it works now!!!! yay!!
([URL]) 

many thanks for your help (=

sheryl
This site was created by Mark "Tarquin" Wilton-Jones.
Don't click this link unless you want to be banned from our site.