2007
03.27
03.27
Sometimes we use javascript to do the data verification check on the client side. Sometimes we change the behavior of an input such as textbox to only accept numbers. To check wheter your clients using Javascript in their environment, add/adapt 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.





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.
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.