Form validation is best done server side but, using javascript, this method will work if javascript is enabled in the client's browser and they don't try to pull a 'fast one' by hacking the script -
First give your two tables each these unique ids:
HTML Code:
<table id="table1" BORDER="3" align='center' >
and
HTML Code:
<table id="table2" BORDER="3" align='center' >
Next, change your onsubmit event like so:
Code:
onsubmit="return validate();"
Finally put this script in the head:
Code:
<script type="text/javascript">
function val(table){
var inps=document.getElementById(table).getElementsByTagName('input')
var texts=new Array()
var tcount=count=0
for (var i_tem = 0; i_tem < inps.length; i_tem++)
if ( inps[i_tem].type=='text' ){
texts[tcount]=inps[i_tem]
tcount++
}
for (var i_tem = 0; i_tem < texts.length; i_tem++)
if ( texts[i_tem].value.length==3&&!isNaN(parseInt(texts[i_tem].value)) )
count++
if (count>3)
return true;
else
return false;
}
function validate() {
if (val('table1')&&val('table2'))
return true;
else {
alert ('You must choose at least 4 course areas in each section,\n and furnish a course level number for each.')
return false;
}
}
</script>
Notes: This only satisfies the requirements you mentioned, any positive, whole 3 digit number may be used in the text fields and the originally selected options may all be retained.
Bookmarks