Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jun 2002
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    validation on forms

    > Please help I'm need to developing websites.
    >
    > How can I validate a group of fields in a form that only need to be
    > required if one other field is required.
    >
    > I have some fields that are required and then other dependent
    > fields. I need to be able to require a few other fields that are
    > dependent on if another field has been populated.
    >
    > here is my code...
    >
    > 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') {
    >
    > 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 (val<min || max<val) 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 == '');
    >
    > }
    >
    >
    > ------------------------
    >
    > <input type="submit" name="Submit" value="Submit"
    > onfiltered="MM_validateForm
    >
    ('Dealer_Company_Name','','R','Dealer_Contact_Name','','R','DealerTele
    >
    phone','','R','Dealer_Review_Mgr_Name','','R','Registered_Company_Name
    > ','','R','Company_Street_Address','','R','Company_City','','R','Comp
    an
    >
    y_State','','R','Company_Zip','','R','Company_Country','','R','Company
    >
    _Telephone','','R','Billing_Contact_First_Name','','R','Billing_Contac
    >
    t_Last_Name','','R','Billing_Contact_Phone','','R','Billing_Contact_Em
    >
    ail','','RisEmail','Billing_Street_Address','','R','Billing_State','',
    > 'R','Billing_City','','R','Billing_Country','','R','Billing_Zip_Code
    ',
    > '','R');return document.MM_returnValue">

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    41 8' 52" N -95 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hmm... it would be better if you just posted the original HTML form (without the MM_BLAH89a7hdsf89blahblahblah), and told us what form fields you want validated rather than posting that Macromedia code.

    That WYSIWYG editor validation is atrocious (and hard to edit)... I would advise not using it, personally...

    Is it possible to present a plain form (only HTML) without the horrible WYSIWYG code that we could validate using plain logic?

    If not, I would personally rewrite the form...

    P.S. I don't mean anything personal against you... but if this is the case then just using the HTML from the form itself and eliminating all of the "generated" javascript code would definitely be in your best interests!

    Last edited by whammy; 06-20-2002 at 02:46 AM.
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •