Jump to content

Ways of including JS files in PHP - NOT 'include'/'require_once'/'<script>' tags


sparklechic007

Recommended Posts

:shrug:

Hi, I'm wondering if anyone can tell me if there's a work around for calling js files in php.  Basically, I have an autosuggest field which is calling from a database.  However, when I try to use the js by using 'require_once' in php if I click on one of the entries on the autosuggest list it won't fill the textfield.  If I include the .js file in <html> at the top of the page I get 'headers already sent (by my configuration file linking to the database).'

 

I've also tried to include the <script> in the php instead using single quotes but this doesn't work. 

 

I can't change my configuration file as it's used by other pages, and I can't really put the form into a separate html file because it uses other code as well for when the actual submit button is sent (this is separate from the autosuggest). 

 

All I'm wondering is if there's another way to call the javascript in the PHP

 

Link to comment
Share on other sites

in MOST php applications (excluding COMET or PUSH implementations) after the php has finished being executed, php exits.. meaning you cannot continue to modify the output the user sees already..

 

php is for the most part server side, with another select few exceptions, but for most WEB APPLICATIONS it is 98% server side, with like I said before, COMET and PUSH applications..

 

JavaScript, however, is a CLIENT SIDE language with another few exceptions.. but for the most part this is the language you will want to utilize to manipulate information already sent to the client (the browser).

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.