phppup Posted March 24, 2012 Share Posted March 24, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/259628-where-to-place-javascript-in-my-php/ Share on other sites More sharing options...
AyKay47 Posted March 24, 2012 Share Posted March 24, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/259628-where-to-place-javascript-in-my-php/#findComment-1330742 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.