I'm writing a small validation script that has to check the maxlength of the form input and adjust the actual length of the form accordingly.
Here's what i'm talking about:
Code: Select all
function checkform() {
var elem = document.getElementById('r001').elements;
for(var i = 0; i < elem.length; i++) {
if(elem[i].type == "text") {
if(elem[i].value.length < elem[i].maxlength) {
//length is not long enough and will be adjusted accordingly
} else {
//length is long enough and will be passed through
}
}else if(elem[i].type == "radio") {
//ignore radio buttons
} else {
//ignore buttons
}
}
return true;
}
<form action="<?php echo $PHP_SELF;?>" method="post" id="r001" name="r001" onsubmit="return checkform()">
<input name="CUST" type="text" size="40" maxlength="40" value="0" />
<input name="Author" type="text" size="20" maxlength="20" value="0" />
</form>
Any help would be greatly appreciated.