Hello and welcome to our community! Is this your first visit?
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 2007
    Thanked 0 Times in 0 Posts

    MM_validateForm() -- question

    I'm adding a text field named city. I'm trying to validate it using MM_validateForm() however I'm not sure how to add it into the javascript.

    Can anyone help out?

    <script type="text/javascript">
    function MM_validateForm() { //v4.0
      if (document.getElementById){
        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=document.getElementById(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 the number '+min+'.\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 name="submit" type="submit" class="submit-button" onclick="MM_validateForm('name','','R','email','','RisEmail','answer','','RinRange4:4','city','message','','R');return document.MM_returnValue" value="Submit" />

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    London, England
    Thanked 2,508 Times in 2,486 Posts
    I don't really understand. That is ghastly DreamWeaver code! Just place the script in the <head> section of your page.

    onclick="MM_validateForm('name','','R','email','','RisEmail','answer','','RinRange4:4','city','message','','R');return document.MM_returnValue" value="Submit" />

    Quizmaster: When counting down, what whole number follows 37?
    Contestant: er, 19.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


    Posting Permissions

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