Jump to content

Where to place JavaScript in my PHP


phppup

Recommended Posts

 

I currently have a Javascript placed at the top of the same file as my HTML form.

 

Now I need to run the file as PHP, and was wondering what the proper protocol and best practice is for the JavaScript (which does some client side validation).

 

Can I leave it as is, at the top of the file  after changing the extention to PHP.

If I put it in a seperate file, should I call it as a JavaScript or as an INCLUDE file.

If I INCLUDE it, should the INCLUDE be a PHP file (that contains the JS, or a JS extention.

 

Does any of this make a difference, or will any method work, leaving it to personal preference?

Link to comment
Share on other sites

1. each language should be kept separate and you should avoid intermingling them (IMO).

2. My advice would be to run any sort of validation using PHP and not JavaScript, as JavaScript can simply be disabled.

3. I normally always link to an external .js page which holds all of the JavaScript code, to keep it away from the design and PHP business layers.

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.