Skip to main content
Participant
October 30, 2007
Question

Add new functions to Validation Form DW8

  • October 30, 2007
  • 1 reply
  • 237 views
Using DW8, I've got a simple form with 4 text fields on it - Meter, Date, Count, VerifyCount - and a Submit button. I've added Form Validation to the fields to make them all required and the Count and VerifyCount required to be a number. What I want to do is modify the JS that DW8 added (function MM_validateForm) to make it 1. Validate that the Date field is actually a date and 2. Compare Count and VerifyCount fields match. If not, then provide an error message like any other validate error in the script.
The javascript code is attached that is created by DW8 for Form Validate - looks standard for number of fields... so really looking to add two new validation types.
--Thanks--
This topic has been closed for replies.

1 reply

Inspiring
October 30, 2007
LTL69 wrote:

> Using DW8, I've got a simple form with 4 text fields on it - Meter, Date,
> Count, VerifyCount - and a Submit button. I've added Form Validation to the
> fields to make them all required and the Count and VerifyCount required to be a
> number. What I want to do is modify the JS that DW8 added (function
> MM_validateForm) to make it 1. Validate that the Date field is actually a date

What do you consider to be a date? Would you put some restraints on it?

e.g.:

isADateObject(formEntry) && isAfter(dateInPast) && isBefore(dateInFuture)


> and 2. Compare Count and VerifyCount fields match. If not, then provide an
> error message like any other validate error in the script.
> The javascript code is attached that is created by DW8 for Form Validate -
> looks standard for number of fields... so really looking to add two new
> validation types.
> --Thanks--

Create your own functions : isADate() and fieldsAreSame()

Then add to form tag:
<form
onsubmit=
"return document.MM_returnValue &&
isADate(this.dateField) &&
fieldsAreSame(this.field1,this.field2)">

You could modify the DW function, too. I could help you if you let me
know your specs for date.
Mick

>
>
> <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)&&d.all) x=d.all; for (i=0;!x&&i<d.forms.length;i++)
> x=d.forms ;
> for(i=0;!x&&d.layers&&i<d.layers.length;i++)
> x=MM_findObj(n,d.layers
.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 );
> 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>
>