Newbie java person here.
I’ve used Dreamweaver to validate text fields in a form but it doesn’t seem to work for drop down lists/menus.
I’ve read some tuts on javascript and still can’t really tell why it’s not working. I’ve ommitted the HTML of the form as it’s alot of text. Let me know if thats needed and I’ll post it as well.
TIA
Here’s the script portion:
[CODE]
<script language=”JavaScript” type=”text/JavaScript”>
<!–
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf(“?”))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_validateForm() { //v4.0
var i,p,q,nm,test,num,min,max,errors=”,args=MM_validateForm.arguments;
for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
if (val) { nm=val.name; if ((val=val.value)!=””) {
if (test.indexOf(‘isEmail’)!=-1) { p=val.indexOf(‘@’);
if (p<1 || p==(val.length-1)) errors+=’- ‘+nm+’ must contain an e-mail address.n’;
} else if (test!=’R’) { num = parseFloat(val);
if (isNaN(val)) errors+=’- ‘+nm+’ must contain a number.n’;
if (test.indexOf(‘inRange’) != -1) { p=test.indexOf(‘:’);
min=test.substring(8,p); max=test.substring(p+1);
if (num<min || max<num) errors+=’- ‘+nm+’ must contain a number between ‘+min+’ and ‘+max+’.n’;
} } } else if (test.charAt(0) == ‘R’) errors += ‘- ‘+nm+’ is required.n’; }
} if (errors) alert(‘The following error(s) occurred:n’+errors);
document.MM_returnValue = (errors == ”);
}
//–>
</script>
Form header:
[CODE]<form action=”res_process.php” method=”post” name=”reservation_form” target=”_self” id=”reservation_form” onSubmit=”MM_validateForm(‘first_name’,”,’R’,’surname’,”,’R’,’phone’,”,’R’,’enter_email’,”,’RisEmail’,’con firm_email’,”,’RisEmail’,’airport’,”,’R’,’sel_area’,”,’R’,’direction’,”,’R’,’town’,”,’R’,’area_ code’,”,’R’,’enter_date’,”,’R’,’hour’,”,’R’,’minute’,”,’R’,’flight_no’,”,’R’,’sel_PAX’,”,’R’,’ address’,”,’R’);return document.MM_returnValue”>
And after the HTML:
[CODE]
<input language=javascript id=btnSubmit style=”FONT-WEIGHT: bold; FONT-SIZE: 8pt; COLOR: navy; FONT-FAMILY: Tahoma” onClick=”if (typeof(Page_ClientValidate) == ‘function’) Page_ClientValidate(); ” tabindex=7 type=submit value=continue name=btnSubmit>
<script language=javascript>
<!–
var Page_Validators = new Array(document.all[“valDirectionRequired”]);
// –>
</script>
<script language=javascript>
<!–
var Page_ValidationActive = false;
if (typeof(clientInformation) != “undefined” && clientInformation.appName.indexOf(“Explorer”) != -1) {
if ((typeof(Page_ValidationVer) != “undefined”) && (Page_ValidationVer == “125”))
ValidatorOnLoad();
}
function ValidatorOnSubmit() {
if (Page_ValidationActive) {
ValidatorCommonOnSubmit();
}
}
// –>
</script>