Results 1 to 2 of 2

Thread: Script wont work

  1. #1
    Join Date
    Jun 2006
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Script wont work

    Hello all, I cannot get this stinkin thing to work. All it does is validate fields on a page. The page is here at http://www.oharanetworks.com/request/quote/
    Whenever you click submit, a box pops up and says that you need to fill in the following information, then you click ok and it just goes onto the send.php page.
    Here is the script:

    Code:
    <script language="javascript">
    function check_submit(e)
    {
    	var msg;
    	var textAll = "An Error occurred. Please make sure that you have completed ALL REQUIRED Fields.";
    	var textfname="";
    	var textlname="";
    	var textcname="";
    	var texttype="";
    	var textpages="";
    	var textdname="";
    	var textphone="";
    	var textemail="";
    	
    	
    	if ((e.fname.value == null) || (e.fname.value == "") || isblank(e.fname.value)) { textfname = "First Name is Required.\n";}
    	
    	if ((e.lname.value == null) || (e.lname.value == "") || isblank(e.lname.value)) { textlname = "Last Name is Required.\n";}
    	
    	if ((e.cname.value == null) || (e.cname.value == "") || isblank(e.cname.value)) { textcname = "Company Name is Required.\n";}
    	
    	if ((e.type.value == null) || (e.type.value == "") || isblank(e.type.value)) { texttype = "Type of Site is Required.\n";}
    	
    	if ((e.pages.value == null) || (e.pages.value == "") || isblank(e.pages.value)) { textpages = "Estimated Number of Pages is Required.\n";}
    	
    	if ((e.dname.value == null) || (e.dname.value == "") || isblank(e.dname.value)) { textdname = "Requested Domain Name is Required.\n";}
    	
    	if ((e.phone.value == null) || (e.phone.value == "") || isblank(e.phone.value)) { textphone = "Phone Number is Required.\n";}
    	
    	if (textphone=="") {
    	  if (!checkphone(e.phone.value)) { 
    	     textphone = "An Error occurred. Please enter a correct phone number. For example: 1-222-333-4545 \n";
    	  }
    	}
    	
    	if ((e.email.value == null) || (e.email.value == "") || isblank(e.email.value)) { textemail = "E-mail address is Required.\n";}
    	
    	if (textemail=="") {
    	  if (!CheckEmail(e.email.value)) { 
    	     textemail = "An Error occurred. Please enter a correct email address. For example: me@mysite.com \n";
    	  }
    	}
    
    	if (e.fname.style) e.fname.style.backgroundColor = textfname != "" ? '#FFCC66':'#FFFFFF';
    	if (e.lname.style) e.lname.style.backgroundColor = textlname != "" ? '#FFCC66':'#FFFFFF';
    	if (e.cname.style) e.cname.style.backgroundColor = textcname != "" ? '#FFCC66':'#FFFFFF';
    	if (e.type.style) e.type.style.backgroundColor = texttype != "" ? '#FFCC66':'#FFFFFF';
    	if (e.pages.style) e.pages.style.backgroundColor = textpages != "" ? '#FFCC66':'#FFFFFF';
    	if (e.dname.style) e.dname.style.backgroundColor = textdname != "" ? '#FFCC66':'#FFFFFF';
    	if (e.phone.style) e.phone.style.backgroundColor = textphone != "" ? '#FFCC66':'#FFFFFF';
    	if (e.email.style) e.email.style.backgroundColor = textemail != "" ? '#FFCC66':'#FFFFFF';
    	
    	if ((textfname == "") && (textlname == "") && (textcname == "") && (texttype == "") && (textpages == "") && (textdname == "") && (textphone == "") && (textemail == "")) { e.submit(); return true; }
    	
    	if (textfname && textlname && textcname && texttype && textpages && textdname && textphone && textemail) {
    		msg = textAll;
    	} else {
    		msg = textfname + textlname + textcname + texttype + textpages + textdname + textphone + textemail;
    	}		
    	
    	alert(msg);
    	return false;
    }
    
    
    function isblank(s)
    {
    	for(var i = 0; i < s.length; i++) {
    		var c = s.charAt(i);
    		if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
    	}
    	return true;
    }
    
    function checkphone(str)
    {
        for( var i=0; i < str.length; i++) {
            var ch = str.substring( i, i+1 );
            if( (ch < "0" || ch > "9") && ch != "-" && ch != "(" && ch != ")" && ch != "x" && ch != "X" && ch != "+") 
                return false;              
        }    
        return true;
    }
    
    function CheckEmail(strEmail) {
    	var i;
    	var getChar;
    
    	if ((Left(strEmail, 1) == "@") || (Right(strEmail, 1) == "@") )
    		return false;
    	
    		getChar = 0;
    	for (i = 0 ; i < strEmail.length ; i++ ) {
    		if (strEmail.charAt(i)=='@'){
    			getChar++;
    		}
    	}	    
    
    	if ( getChar != 1 )
    		return false;
    
    	var email1;
    	var email2;
    	var temail;
    	
    	temail = strEmail.split('@')
    	email1 = temail[0].replace(/\s/g, "");
    	email2 = temail[1].replace(/\s/g, "");	
    	
    	var cemail;
    	cemail = strEmail;
    	cemail = cemail.replace(/\@/g, "");	
    	cemail = cemail.replace(/\./g, "");	
    	
    	if (cemail.length == 0)
    		return false;
    	
    	var allow;
    	allow = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_-";
    	for(i = 0 ; i < cemail.length; i++ )
    		if (allow.indexOf(cemail.charAt(i)) < 0 )
    			return false;
    
    	if (Left(email1, 1) == '.')
    		return false;
    
    	
    	if (Left(email2, 1) == '.' || Right(email2, 1) == '.' || email2.replace(/\./g, "").length == email2.length)
    		return false;
    
    	if (email2.indexOf("..") >= 0 )
    		return false;
    
    	if (Left(email2, 1) == '-' || Right(email2, 1) == '-')
    		return false;
    
    	if (Left(email2, 1) == '_' || Right(email2, 1) == '_')
    		return false;
    	
    	return true;
    }
    
    function Left( sourceStr, charIdx ) {
    	if((sourceStr==null) || (sourceStr=="")) return "";
    	return sourceStr.substring(0, charIdx);
    }
    
    function Right( sourceStr, charIdx ) {	
    	if((sourceStr==null) || (sourceStr=="")) return "";
    	return sourceStr.substring(sourceStr.length-charIdx, sourceStr.length);
    }
    </script>
    Please help, I dont know wats wrong. Thanks.

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    We need to see the code that passes e to check_submit() as well.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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
  •