1

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">
<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">
<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>
<!-- 
4
  • 1
    Would be easier if you show the code. Commented Dec 4, 2009 at 15:12
  • Explain "PHP navigation page format" Commented Dec 4, 2009 at 15:15
  • each section has a subsection which has mutiple reports, these reports have use a report class file for that formats and contains all the user functions this report class is where the javascript source reference is at. Commented Dec 4, 2009 at 15:28
  • Please post the rendered HTML code. We can't guess what your PHP code is going to output. Commented Dec 4, 2009 at 15:33

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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

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.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.