July 1, 201214 yr I'm making a website and I want it to run perfectly without Javascript, but when Javascript is enabled that there are a couple of enhancements like a form validation without reloading the page. Of course, if the user has Javascript disabled I want the website to work to and go on with the PHP. So my question is: how do I run Javascript if javascript is enabled and run PHP when it's disabled? I'm quite new to Javascript and googled some stuff but didn't find anything useful.
July 1, 201214 yr You don't. You run PHP validation AND JavaScript validation. That way, when they don't have JS enabled, it doesn't fail to validate, and when they do, you don't waste bandwidth on a server-side validation request. Edited July 1, 201214 yr by andyl
July 1, 201214 yr Author You don't. You run PHP validation AND JavaScript validation. That way, when they don't have JS enabled, it doesn't fail to validate, and when they do, you don't waste bandwidth on a server-side validation request. Then how do you make it so if Javascript is enabled it stops the PHP validation that goes to another page? Because I don't want it to go to another page when JS is enabled. Edited July 1, 201214 yr by Dreeass
July 1, 201214 yr You'll need to stop the form submitting, using return false, or e.preventDefault() if you're using jQuery. It's best practice to validate server-side every time. People can bypass validation by simply changing the JS functions on your page. They can't do that with server-side scripts. Edited July 1, 201214 yr by andyl
Create an account or sign in to comment