Results 1 to 2 of 2

Thread: Help with Dreamweaver Validate form javascript

  1. #1
    Join Date
    Jan 2009
    Posts
    82
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Help with Dreamweaver Validate form javascript

    I have this javascript Dreamweaver creates by default to validate a form from errors. I would like to run another script IF there are no errors and the form is submitted, but I just can't figure out where the form is submitted in this javascript. Basically I want to stop duplicate submissions.


    Here's what I want to run when the form is submitted:

    Code:
    document.getElementById('loadingmsg').innerHTML = "<img src='/images/ajax-loadergray.gif' /> Working... ";
    Here's the Dreamweaver default validation form (I'm ok with JS but I can't read this well):

    Code:
    <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 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>

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,926
    Thanks
    43
    Thanked 3,192 Times in 3,155 Posts
    Blog Entries
    12

    Default

    It's hard to say with certainty without seeing how this code is assigned to the form. But it looks like the form's submission is contingent upon this value being true:

    Code:
    document.MM_returnValue = (errors == '');
    If there are no errors, this will be true, and presumably the form submits. As I say I cannot be certain though without seeing the form, preferably the entire page. But if I'm right, and successful submission does not cause the page to reload or to load another page, this should work (addition highlighted):

    Code:
    <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 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 == '');
        if(document.MM_returnValue){
            document.getElementById('loadingmsg').innerHTML = "<img src='/images/ajax-loadergray.gif' /> Working... ";
        }
    } 
    
    }
    //-->
    </script>
    The browser cache may need to be cleared and/or the page refreshed to see changes.

    If you want more help, please include a link to the page on your site that contains the problematic code so we can check it out.
    Last edited by jscheuer1; 08-23-2013 at 08:27 AM. Reason: spelling
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Similar Threads

  1. Need to validate form by PHP.
    By shakti in forum PHP
    Replies: 2
    Last Post: 01-20-2009, 05:45 PM
  2. validate form
    By darren9 in forum JavaScript
    Replies: 1
    Last Post: 07-15-2008, 09:05 AM
  3. Replies: 2
    Last Post: 05-09-2008, 03:01 AM
  4. Please help: javascript to validate checkbox and textbox before submitting form
    By alohatrojan in forum Looking for such a script or service
    Replies: 2
    Last Post: 10-30-2007, 04:22 PM
  5. what's validate(e) in form validation
    By mtran in forum JavaScript
    Replies: 6
    Last Post: 11-03-2006, 09:14 PM

Bookmarks

Posting Permissions

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