title: Writing JS in PHP with document.write
body: <p>This is failing but i dont know how to make it work.</p>
  
  <p>I have a php array:</p>
  
  <pre><code>$swipe_list = array('customers.html', 'index.html', 'atr_backplane.html');
  </code></pre>
  
  <p>This is to know which pages have carousels and need touch support.</p>
  
  <p>so i check the page in php and if its listed the JS will check its a touch device and write the addional js mobile file.</p>
  
  <p>is it because the server script trys ti run before the js can detect at the client side??</p>
  
  <pre><code>&lt;?php
  if(in_array($selected, $swipe_list)){ ?&gt;
  &lt;script type="text/javascript"&gt;
  
  function isTouchDevice(){ document.write('&lt;script type="text/javascript" src="js/jquery.mobile.custom.min.js"&gt;&lt;/script&gt;')
  }
  
  &lt;/script&gt;            
  &lt;?php }?&gt;
  &lt;?php if(!in_array($selected, $exclude_list)){       
  print '&lt;script type="text/javascript" src="js/camera.js"&gt;&lt;/script&gt;';
  }
  ?&gt;
  </code></pre>