Web Hosting Talk







View Full Version : Preventing "JavaScript disabled users" to send unvalidated forms.


BurakUeda
07-27-2005, 08:35 AM
This simple code I wrote, and just wanted to share.

Actually you can (and you should anyway) always check the post variables in the second page, but this code prevents users clicking "submit" buttons if JavaScript disabled:


<SCRIPT TYPE="TEXT/JAVASCRIPT" LANGUAGE="JAVASCRIPT">
function enable(){
var formQ = document.forms.length;
for(var xx=0; xx<formQ; xx++) {
var formElementQ = document.forms[xx].elements.length;
for(var yy=0; yy<formElementQ; yy++){
if(document.forms[xx].elements[yy].type.toLowerCase()=="submit")
{
document.forms[xx].elements[yy].disabled = false;
}
}
}
}
</SCRIPT>


Put this on top of your page, and call the function from BODY tag. You also have to disable all your submit buttons:

<BODY onLoad="enable()">
<INPUT TYPE="Submit" NAME="Send" DISABLED>

adaml
07-27-2005, 03:14 PM
:)

This might come in use one day!

$_patch
01-04-2006, 01:18 PM
for user inputs, there are two stages of test that must be done...

1. on client side, this will lessen the frustration of the user. he wants to know immediately the error.

2. server side, for users that bypass the client page, you must also check the inputs on the server side.

more important checking is on #2 because all your system depends on that checking. the #1 checking is only for improving user experience.