How to check if Javascript is enabled on the client side using php

By: mendesdomnic

September 3, 2009 3:58 pm





You might be using validations for your form on client side using Javascript. It may arise that client side Javascript is disabled, given this scenario your validations will go for a toss.

You can check in your php if Javascript is enabled on client side using the following method.

Add a hidden input in your form in the <noscript> tag. The contents of noscript tag are rendered on a browser with Javascript disabled:

<form id="" action="" method="post">
		<input name="js_enabled" type="hidden" value="1">
	<input id="email" name="email" size="30" class="required email" ><br>
	<input id="submit_data" value="Submit" type="submit"><br>

Now the following will be the php code to check whether Javacript is enabled:


// Check if Javascript is enabel from hidden value in <noscript></noscript>
$browser_check = 0;
	$browser_check = $_POST['js_enabled'];

if ($browser_check == 1) {
	echo ' Javascript is disabled on your system';


This is useful if you use ajax submission of form. Say to check if email exists and display the same in error div. Or maybe other scenarios that may suit your requirements.

0 votes, average: 0.00 out of 50 votes, average: 0.00 out of 50 votes, average: 0.00 out of 50 votes, average: 0.00 out of 50 votes, average: 0.00 out of 5 (0 votes, average: 0.00 out of 5)
You need to be a registered member to rate this post.

Tags: , ,
Categories: Enterprise Linux, Technical Solutions

Disclaimer: As with everything else in the SUSE Blog, this content is definitely not supported by SUSE (so don't even think of calling Support if you try something and it blows up).  It was contributed by a community member and is published "as is." It seems to have worked for at least one person, and might work for you. But please be sure to test, test, test before you do anything drastic with it.