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 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    javascript coding for all errors in a single alert box,not understanding error ?

    Code:
    <html>
        <script>
            function isFormValid() 
    {	
    	var userF = document.getElementById('FName').value;
    	var userL = document.getElementById('LName').value;
    	var userPW = document.getElementById('pw').value;
    	var userPW2 = document.getElementById('pw2').value;
    	var userEmail = document.getElementById('email').value;
            var userMobile=document.getElementById('mobile').value;
            var userAddress=document.getElementById('address1').value;
            var userCity=document.getElementById('city').value;
            var userState=document.getElementById('state').value;
            var userZip=document.getElementById('zip').value;
            var gen=document.form.radios;
    	var NameFormat = /^[A-Za-z]{2,12}$/;
    	var PWFormat = /^[A-Za-z0-9{6,12}$]/;
            var Mobileformat=/^[0-9]{10}$/;
            var Emailformat=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
    	var retVal = true;
    	var errorMsg = "";
    	
    	if (!NameFormat.test(userF))
    		{
    		errorMsg = "First Name is required and should only have letters. 2-12 letters max\n";
    		retVal = false;
    		}
    	if (!NameFormat.test(userL))
    		{
    		errorMsg = errorMsg + "Last Name is required and should only have letters. 2-12 letters max\n"; 
    		retVal = false;
                }
            
            if ( (gen[0].checked == false ) && ( gen[1].checked == false ) ){
                errorMsg=errorMsg+"please check your gender: Female or Male\n";
          
                return retVal =false;
                }
    	if(!Mobileformat.test(userMobile)){
                
                errorMsg = errorMsg+"Mobile number is required and should only have 10 numbers \n";
    		retVal = false;
            }
            if(!Emailformat.test(userEmail)){
                
                errorMsg = errorMsg+"please eneter a valid email id \n";
    		retVal = false;
            }
            if (!PWFormat.test(userPW))
    		{
    		errorMsg = errorMsg + "Password is required and should only have letters and numbers. 6-12 letters max\n";
    		retVal = false;
    		}
    	if (userPW != userPW2)
    		{
    		errorMsg = errorMsg + "Passwords do not match.\n";
    		retVal = false;
    		}
            if(!PWformat.test(userAddress)){
                errorMsg = errorMsg + "please enter valid address \n";
    		retVal = false;
                
            }       
            if(userCity.value==""){
                   errorMsg=errorMsg+"please enter your city\n";
                 
                    return retVal =false;
                }    
                if(state.value==""){
                    errorMsg=errorMsg+"please enter your state\n";
                    return retVal =false;
                }   
                if( zip.value == "" || isNaN(zip.value ) ||zip.value.length != 6 ){
                    errorMsg=errorMsg+"Please provide a zip in the format ######.\n";
                   
                    return retVal =false;
                }
    	if (!retVal)
    		{
    		alert( errorMsg);
    		}
    	return retVal;
    }
            </script>
    
    
    <form action="mailto:hummdedum@felloff.com" method="post" name="form" onSubmit="return isFormValid();">
    
    * First Name: <input type="text"  name="FName" id="FName" onblur="checkFName();"/><label id="labelFName"></label><br />
    
    * Last Name: <input type="text" name="LName" id="LName" onblur="checkLName();"/><label id="labelLName"></label><br />
    
    * Gender<input type="radio" name="radios" value="male" id="gen" onblur="checkgen();">Male <input type="radio" name="radios" value="Female">Female<label id="labelGender"></label><br />
    
    * E-Mail: <input type="text" id="email" name="Email" onblur="checkEmail();"/><label id="labelEmail"></label><br />
    
    * Mobile Number<input type="text" name="mobilenumber" id="mobile" onblur="checkmobile();"><label id="labelMobile"></label><br />
    
    * Password: <input type="password" id="pw" name="Password" onblur="checkpw();"/><label id="labelpw"></label><br />
    
    *Re-type Password: <input type="password" name="2Password" id="pw2" onblur="checkpw2();" /><label id="labelpw2"></label><br />
    
    * Address1<input type="text" name="address" id="addressid1" onblur="checkaddress1();"><label id="labelAddress1"></label><br />
    
    Address2<input type="text" name="add2"><label id="labelAddress2"></label><br />
    
    Address3<input type="text" name="add3"><label id="labelAddress3"></label><br />
    
    *City<input type="text" name="cityname" id="city" onblur="checkcity();"><label id="labelCity"></label><br />
    
    *State<input type="text" name="statename" id="state" onblur="checkstate();"><label id="labelState"></label><br />
    
    *ZIP<input type="text" name="zip1" id="zip" onblur="checkzip();"><label id="labelZip"></label><br />
    
    	<input type="submit" value="Submit" />
    	<input type="reset" value="reset" />
    
    </form>
    </html>
    Last edited by VIPStephan; 11-01-2012 at 04:19 PM. Reason: added code BB tags

  • #2
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,879
    Thanks
    6
    Thanked 1,035 Times in 1,008 Posts
    If you post any code please put it in between [CODE][/CODE] tags. It makes scanning your posts much easier. You can do this by clicking the small ‘#’ icon above the reply field.

  • #3
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    Well, at a cursory glance, don't name your form "form". Don't use reserved words as IDs or Names.

    Other than that, please be more descriptive. What are you not understanding?
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,253
    Thanks
    203
    Thanked 2,557 Times in 2,535 Posts
    <form action="mailto:hummdedum@felloff.com"

    The trouble with using this long-obsolete method (mailto) to send form results is its unpredictability. The method it is highly dependent on the browser in use
    and the email client in use (some people have only Yahoo, Gmail or Hotmail). In particular, your visitor must have Outlook or Outlook Express or Windows Live Mail as the default client for this to work correctly. Even if your visitor is using Internet Explorer, but the default mail client is different (e.g. Eudora or Thunderbird), your mailto form will not work. With all of the browser troubles, you're likely to lose about half of your users' messages. Most of the email clients that can successfully send a mail will prompt the user with a somewhat threatening security dialog prior to sending - this can scare many users from continuing. Other users will not wish to reveal their email address. Also, what about people with Javascript disabled?

    In addition, if you place an unobfuscated email address in your webpage, the bots will quickly find it and inundate you in spam.

    Modern browsers no longer accept mailto: as a form action - they simply open the email program (if any) and ignore the form. If you are going to use a form then use a server-side CGI formmail script as the action - there are several good free ones out there.

    For a simple PHP form feedback script see:- http://www.thesitewizard.com/archive/feedbackphp.shtml
    or http://www.felgall.com/php2.htm

    Use your error console to expose errors.

    var userAddress=document.getElementById('address1').value; // no such field - id is addressid1

    Because you have defined var retVal = true; any mistake of this kind will cause the script to stop executing and return true.

    if (!NameFormat.test(userF)) // no function NameFormat



    If at first you don't succeed, redefine success.
    Last edited by Philip M; 11-01-2012 at 05:55 PM.

    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.

  • #5
    Senior Coder Logic Ali's Avatar
    Join Date
    Sep 2010
    Location
    London
    Posts
    1,028
    Thanks
    0
    Thanked 207 Times in 202 Posts
    The first error is

    TypeError: document.getElementById("address1") is null

    Line: 12
    Referring to this line:

    Code:
         var userAddress=document.getElementById('address1').value;
    See if you can find the form element to which it refers.


  •  

    Tags for this Thread

    Posting Permissions

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