views:

130

answers:

3

I am trying to reference a JavaScript file, containing a table sort function, in a PHP file. Everything functions the way it should, but once I add the code below to my PHP report page it causes issues with the format of the tabs on my navigation page. The same issue comes up if I add a random document.write outside of the PHP code. Not a huge issue but rather unsightly to the user.

Is there a better way to reference the JavaScript source doc that will not interfer with my php navigation page format? I feel like there is a simple fix that I am not grasping.

<script language="JavaScript" src="include/sorttable.js"></script>

Also used an the PHP echo inside the PHP tags to make the call, same issue.

Here is part of the navigation code for the tabs that the format issue is coming up on.

<?php

//////////////////////////////////////////////////////////////////////////////////////////////////
function start_page_printer_friendly(
      $section = "home",
      $headContents = null,
      $bodyAttributes = null
)
//////////////////////////////////////////////////////////////////////////////////////////////////

{?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html>
<head>
<title><?php print $page_title; ?></title>
<link href="/trellis_portal/include/portal.css" media="screen"
   rel="Stylesheet" type="text/css" />
      <?php if ( ! is_null($headContents)) { print $headContents; } ?>
   </head>

<body onload="printpage();" <?php if ( ! is_null($bodyAttributes)) { print $bodyAttributes; } ?>>
   <script language="JavaScript">
      <!--
         function printpage() { window.print(); }
      -->
   </script>
<br />
<?php                     
}

//////////////////////////////////////////////////////////////////////////////////////////////////
function start_page( $section = "home",
                     $subsection = null,
                     $headContents = null,
                     $bodyAttributes = null
                   )
//////////////////////////////////////////////////////////////////////////////////////////////////
{   
    if (isset($_GET['printer']))
    {
     start_page_printer_friendly();
     return;
    }
   $section = strtolower($section);

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html>
<head>
<title><?php print $page_title; ?></title>

 <?php if ( ! is_null($headContents)) { print $headContents; } ?>
   </head>

<body class=" yui-skin-sam" <?php if ( ! is_null($bodyAttributes)) { print $bodyAttributes; } ?>>
<br />


<div id="header">
<ul>
<!-- 
   <li><a class="<?php print tabSelector($section, 'executive'); ?>"
      href="/trellis_portal/portal.php?section=executive&title=Executive">Executive</a></li>
   <li><a
      class="<?php print tabSelector($section, 'community'); ?>"
      href="/trellis_portal/portal.php?section=community&title=Community">Community</a></li>
-->   
   <li><a class="<?php print tabSelector($section, 'trellis'); ?>"
      href="/trellis_portal/portal.php?section=trellis&title=Trellis">Trellis</a></li>
<!--
+2  A: 

I don't really understand the situation yet, but you need to be aware that there is nothing PHP related on your page, only HTML/CSS/Javascript code that happened to be generated by PHP. So you need to look into your HTML code and see what the problem is there. You may then want to update your question with actual HTML code.

Pekka
A: 

SCRIPT tags, in themselves, cannot affect elements or layout within the page.

Your problem is likely elsewhere. To debug this I would ignore the PHP and focus on the HTML output and look for unclosed tags and invalid markup etc.

michael
+2  A: 

I still don't get what you expect but one thing I can see already: EVERYTHING outside is literally transposed, thus

?>
<!DOCTYPE...

will introduce an extra whitespace (newline) at the start before DOCTYPE.

Also the ending of the script ( --> ) will generate JS syntax error. It is valid HTML but must be commented out ( //--> ) in JS.

s.
thanks a bunch your post pushed me in the right direction. Location, Location, Location
Stumps