2007
03.27

JavaScript has become more and more important part of Web Application. Often, it does a crucial role such as doing the data verification check on the client side. Quite often also, we use JavaScript to limit the behavior of a field to suit our need. For example, making a textbox to only accept numbers.

But all this fancy ideas will not work if the JavaScript is disabled. To check wheter your user have their Javascript enabled in their environment, add the following snippets into your form:

<head>
<script type="text/javascript">
<!--
function checkJavascript()
{ 
    var obj = document.getElementById('javascriptCheck');
    obj.value ="1";
} 
//-->
</script>
</head>
<body onload="checkJavascript();">
   <form><input type="hidden" id="javascriptCheck" name="javascriptCheck" value="0" />
       ....
       <!-- put the remaining form in inputs here -->
      ....
   </form>
</body>

 

On the server you will need to check is the ‘javascriptCheck’ variable’s value is ‘1’. If it is, it means Javascript is enabled.

GD Star Rating
loading...

Incoming Search Term

Advertise Here

2 comments so far

Add Your Comment
  1. The much more appropriate DOM-style access would be:

    document.forms[’form_name’].elements[’javascriptCheck’].value = 1;

    Then leave the input as:
    <input type=”hidden” name=”javascriptCheck” value=”0″>

    Sorry about that! Stupid me of me to think markup was enabled on your blog.

  2. A very good suggestion. Looking at my code again, it did not even check for null value. Although I could say that since this is code into our own form, the element should be there.

    But always checking for null value is actually a good habit.