PDA

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



admans
08-10-2005, 08:59 AM
Preventing "JavaScript disabled users" to send unvalidated forms.

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>

commes
08-31-2005, 16:30 PM
woah, again you made a new code, good job and keep up the awesome work!