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
    Jul 2004
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How can I use javascript for email confirmation

    This script originated from Dreamweaver. What I want to do is plug in an email confirmation (like the one when you register for this website) with what Dreamweaver has already supplied.
    I'm having trouble understanding what alot of it does as I'm a newb to javascript.
    I know how to with PHP but I'd rather use java as it doesn't actually process the page until all the fields are filled in correctly.
    This checks that all required fields have been filled in, as well as checking for valid email address, valid date format and time.
    Now I want to plug in the script a confirmation that both instances of the email address match.
    TIA
    Here's the code:

    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>
    Here's the form (the relevant part: (yes it's messy but it works and I really want to get this page up)
    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','confirm_email','','RisEmail','town','','R','airport','','R','direction','','R','area_code','','R','month','','R','day','','R','year','','R','flight_no','','R','address','','R','hour','','R','minute','','R','sel_PAX','','R');return document.MM_returnValue">
    
    <input name="enter_email" type="text" id="enter_email" size="40" maxlength="40">
    
    <input name="confirm_email" type="text" id="confirm_email" size="40" maxlength="40">
    
    <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>
    More script:

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

  • #2
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    One of the problems with using Dreamweaver to write code is that it returns over bloated, non-indented, non-intutitive code which is hard to read and follow. Quite frankly, the few moments I looked at that Dreamweaver Mickey Mouse code, it gave me a headache.....

    Therefore, without touching that mess.
    The below should work for your needs of confirming that the two email inputs match.

    Code:
    <input name="enter_email" type="text" id="enter_email" size="40" maxlength="40">
    
    <input name="confirm_email" type="text" id="confirm_email" size="40" maxlength="40"
    onchange="if(this.form.enter_email.value==''){
    alert('You must first enter your email address above');
    this.value='';this.form.enter_email.focus()}
    else if(this.value!=this.form.enter_email.value){
    alert('Your email addresses do not match\nPlease try again.');
    this.value='';this.form.enter_email.value='';
    this.form.enter_email.focus()}">
    FWIW: You could also use onfocus to check if the first field is empty and if so, alert and set focus to it to be filled out before the user can fill in the confirm field....

    .....Willy


  •  

    Posting Permissions

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