title: PHP + JQuery - How to use these two together? Please see my example
body: <p>I have a php based website. As in, all of the pages html is output via php.</p>
  
  <p>Here is a simple example:</p>
  
  <pre><code>&lt;?php
  ob_start();
  
  $pageStart = '
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
  &lt;title&gt;MY WEBSITE PAGE&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;p&gt;CONTENT&lt;/p&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  ';
  
  echo $pageStart;
  exit;
  ?&gt;
  </code></pre>
  
  <p>What i would like to do is make use of some jquery in this page.</p>
  
  <p>So naturally my first attempt was to include the script inside of the php variable like so:</p>
  
  <pre><code>&lt;?php
  ob_start();
  
  $pageStart = '
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
  &lt;title&gt;Untitled Document&lt;/title&gt;
  
  &lt;script type="text/javascript"&gt;
      var datefield=document.createElement("input")
      datefield.setAttribute("type", "date")
      if (datefield.type!="date"){ //if browser doesn't support input type="date", load files for jQuery UI Date Picker
          document.write('&lt;link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" /&gt;\n')
          document.write('&lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"&gt;&lt;\/script&gt;\n')
          document.write('&lt;script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"&gt;&lt;\/script&gt;\n')
      }
  &lt;/script&gt;
  
  &lt;script type="text/javascript"&gt;
  if (datefield.type!="date"){ //if browser doesn't support input type="date", initialize date picker widget:
      jQuery(function($){ //on document.ready
          $('#birthday').datepicker();
      })
  }
  &lt;/script&gt;
  
  &lt;/head&gt;
  &lt;body&gt;
  &lt;p&gt;CONTENT&lt;/p&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  ';
  
  echo $pageStart;
  exit;
  ?&gt;
  </code></pre>
  
  <p>Now, I use dreamweavers code editor, which due to the syntax highlighting feature, will point out the masses of syntax errors produced in this. </p>
  
  <p>So i at first attempted to slash out these errors. This failed.</p>
  
  <p>So i tried changing the "s to 's, and visa versa, until the errors were gone. This failed too as it seems the script will not validate in this manner.</p>
  
  <p>So i read a few tutorials, and found this one:</p>
  
  <p><a href="http://www.techrepublic.com/article/javascript-behaviors-within-php/1045061" rel="noreferrer">JavaScript and PHP may each bring great potential to any Web development effort, but they don&#039;t always play nice together. Read about the problems.</a></p>
  
  <p>And the way I understand it, is that you'd need to include the js rather than have it as part of your php directly.</p>
  
  <p>So have a file called page.php and another called jquery.php. So I decided to try and modify this idea to suite my problem.</p>
  
  <p>So i started with something like this - index.php:</p>
  
  <pre><code>&lt;?php
  ob_start();
  
  $pageStart = '
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
  &lt;title&gt;MY WEBSITE PAGE&lt;/title&gt;
  '. include $_SERVER['DOCUMENT_ROOT'] . '/../../path/to/include/datepicker.php'.'
  &lt;/head&gt;
  &lt;body&gt;
  &lt;p&gt;CONTENT&lt;/p&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  ';
  
  echo $pageStart;
  exit;
  ?&gt;
  </code></pre>
  
  <p>And - datepicker.php:</p>
  
  <pre><code>&lt;script language="Javascript"&gt;
      var datefield=document.createElement("input")
      datefield.setAttribute("type", "date")
      if (datefield.type!="date"){ //if browser doesn't support input type="date", load files for jQuery UI Date Picker
          document.write('&lt;link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" /&gt;\n')
          document.write('&lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"&gt;&lt;\/script&gt;\n')
          document.write('&lt;script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"&gt;&lt;\/script&gt;\n')
      }
  &lt;/script&gt;
  &lt;script language="Javascript"&gt;
  if (datefield.type!="date"){ //if browser doesn't support input type="date", initialize date picker widget:
      jQuery(function($){ //on document.ready
          $('#birthday').datepicker();
      })
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>Now there are no syntax errors in either page, great... So I try it, half expecting things to finally just work...</p>
  
  <p>Nope... Fatal Error: failed to open stream: No such file or directory blah blah. This error relates to the include that i added. So okay, even though the file is there, it is not being validated as php because there are no opening and closing php tags.</p>
  
  <p>So I add them... Annnd... A page full of syntax errors again!</p>
  
  <p>So my question is this:</p>
  
  <p>Could some please share some knowledge and explain to me roughly how this process actually works. Whats the deal with all the syntax errors, and how are you supposed to go about a task like this?</p>
  
  <p>I believe it is possible, and yes it would ceratinly be easier if i was not outputting the entire html via php. But this is a simple example and my actual design is alot more complex. It requires for the different parts of the page to be broken up into variables, in order to place those bits and peices when needed, dynamically.</p>
  
  <p>Any input, suggestions, or insight would be greatly appreciated; and any links to pages or tutorials that cover this would also be greatly appreciated.</p>
  
  <p>Thank You!!</p>