www.webdeveloper.com
Recent Articles
  • Finding Slow Running Queries in ASE 15
  • A More Advanced Pie Chart for Analysis Services Data
  • Adobe AIR Programming Unleashed: Working with Windows
  • Performance Testing SQL Server 2008's Change Data Capture Functionality
  • The ABC's of PHP: Introduction to PHP
  • How to Migrate from BasicFiles to SecureFiles Storage
  • Why the Twitter Haters Are Wrong
  • User Personalization with PHP: Beginning the Application
  • Whats in an Oracle Schema?
  • Lighting Enhancement in Photoshop
  •  

    Go Back   WebDeveloper.com > Client-Side Development > JavaScript

    JavaScript JavaScript (not Java) Discussion and technical support, including AJAX and frameworks (JQuery, MooTools, Prototype...)

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1  
    Old 11-07-2009, 02:53 AM
    corpsys2000 corpsys2000 is offline
    Registered User
     
    Join Date: Nov 2009
    Posts: 1
    JAVASCRIPT: validation/form mail problem... HELP!!!!

    I am having an issue. First here is the scripts:

    Script 1 - Form Validation:

    Code:
    function formCheck(formobj){
    	// Enter name of mandatory fields
    	var fieldRequired = Array("ATTUID", "cname", "CBN", "WTN", "cbt", "cbdm", "cbdd", "case", "notes", "issue", "modem", "power", "ethernet", "dsl", "internet", "os", "filters", "router", "firewall", "ts1", "ts2");
    	// Enter field description to appear in the dialog box
    	var fieldDescription = Array("ATTUID", "Contact Name", "CBN", "WTN", "Call Back Time", "Call Back Date - Month", "Call Back Date - Day", "Case Number", "Reason For Call Back", "Issue Type", "Modem Model", "Power", "Ethernet", "DSL/Broadband", "Internet", "OS", "Filters", "Router", "Firewall", "Troubleshooting Step 1", "Troubleshooting Step 2");
    	// dialog message
    	var alertMsg = "Please complete the following fields:\n";
    	
    	var l_Msg = alertMsg.length;
    	
    	for (var i = 0; i < fieldRequired.length; i++){
    		var obj = formobj.elements[fieldRequired[i]];
    		if (obj){
    			switch(obj.type){
    			case "select-one":
    				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
    					alertMsg += " - " + fieldDescription[i] + "\n";
    				}
    				break;
    			case "select-multiple":
    				if (obj.selectedIndex == -1){
    					alertMsg += " - " + fieldDescription[i] + "\n";
    				}
    				break;
    			case "text":
    			case "textarea":
    				if (obj.value == "" || obj.value == null){
    					alertMsg += " - " + fieldDescription[i] + "\n";
    				}
    				break;
    			default:
    			}
    			if (obj.type == undefined){
    				var blnchecked = false;
    				for (var j = 0; j < obj.length; j++){
    					if (obj[j].checked){
    						blnchecked = true;
    					}
    				}
    				if (!blnchecked){
    					alertMsg += " - " + fieldDescription[i] + "\n";
    				}
    			}
    		}
    	}
    
    	if (alertMsg.length == l_Msg){
    		return true;
    	}
    	else{
    		alert(alertMsg);
    		return false;
    	}
    }
    Script 2 - Web Form to Client Email Generator

    Code:
    function emailForm()
    { 
    
    
      var cent = document.MemoForm.cent.value;
      var attuid = document.MemoForm.ATTUID.value;
      var approved = document.MemoForm.approved.value;
      var issue = document.MemoForm.issue.value;
      var cname = document.MemoForm.cname.value;
      var modem = document.MemoForm.modem.value;
      var power = document.MemoForm.power.value;
      var ethernet = document.MemoForm.ethernet.value;
      var cbt = document.MemoForm.cbt.value;
      var cbdm = document.MemoForm.cbdm.value;
      var cbdd = document.MemoForm.cbdd.value;
      var CBN = document.MemoForm.CBN.value;
      var WTN = document.MemoForm.WTN.value;
      var dsl = document.MemoForm.dsl.value;
      var cas = document.MemoForm.cas.value;
      var internet = document.MemoForm.internet.value;
      var ethernet = document.MemoForm.ethernet.value;
      var os = document.MemoForm.os.value;
      var filters = document.MemoForm.filters.value;
      var notes = document.MemoForm.notes.value;
      var router = document.MemoForm.router.value;
      var firewall = document.MemoForm.firewall.value;
      var ts1 = document.MemoForm.ts1.value;
      var ts2 = document.MemoForm.ts2.value;
      var ts3 = document.MemoForm.ts3.value;
      var ts4 = document.MemoForm.ts4.value;
      var ts5 = document.MemoForm.ts5.value;
    
    var email = cent ;
    var subject = "Callback needed on " + cbdm + "/" + cbdd + " at " + cbt + "." ; 
    var body = "CALLBACK DETAILS" + "%0D%0D ATTUID: " + attuid + "%0D Approved By: " + approved + "%0D%0D Caller: " + cname + "%0D WTN: " + WTN + "%0D CBN: " + CBN + "%0D Case: " + cas + "%0D%0D Notes: " + "%0D " + notes + "%0D%0D TROUBLESHOOTING DETAILS" + "%0D%0D Issue: " + issue + "%0D Modem: " + modem + "%0D Pwr: " + power + "%0D Enet: " + ethernet + "%0D DSL: " + dsl + "%0D Inet: " + internet + "%0D%0D OS: " + os + "%0D Filters: " + filters + "%0D Firewall: " + firewall + "%0D Steps Taken: " + "%0D%0D -" + ts1 + "%0D -" + ts2 + "%0D -" + ts3 + "%0D -" + ts4 + "%0D -" + ts5;
    
    
    var mailto_link = 'mailto:'+email+'?subject='+subject+'&body='+body; 
    
    win = window.open(mailto_link,'emailWindow'); 
    if (win && win.open &&!win.closed) win.close(); 
    }
    The problem is that even if the validation comes back with missing fields the second scrip will still generate a cleint email, minus the missing information. The validation error box pops up behind the newly cenerated email. I am trying to make it so if validation says that fields are missing the second script will not run. Any ideas how to do this?
    Reply With Quote
      #2  
    Old 11-07-2009, 05:48 AM
    astupidname astupidname is offline
    Registered User
     
    Join Date: Oct 2008
    Location: U.S.
    Posts: 588
    Well, nothing's really jumping out at me, and you have not shown how you are invoking the formCheck and emailForm functions (In the future don't leave key things like that out -you are very lucky to get a response at all without that info). But I guess if it were me, I would probably do something along the lines of: <form action="yadayadayada.php" method="post" onsubmit="return formCheck(this);"> or I would set it via script to the form object, whatever. Then I would insert into the formCheck function in the final 'if' statement:
    Code:
     if (alertMsg.length == l_Msg){
                    emailForm(formobj); //pass the reference to the form, lighten the code in emailForm a bit..
      return true;
     }
    And there is really no need that I know of for the following in the emailForm function:
    Quote:
    win = window.open(mailto_link,'emailWindow');
    if (win && win.open &&!win.closed) win.close();
    Could replace that with:
    Code:
    window.location.href = mailto_link;
    Just my observations, hope it helps.
    Reply With Quote
    Reply

    Bookmarks


    Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
     
    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is Off
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 06:53 AM.



    Acceptable Use Policy

    internet.comMediabistrojusttechjobs.comGraphics.com

    WebMediaBrands Corporate Info


    Advertise | Newsletters | Feedback | Submit News

    Legal Notices | Licensing | Permissions | Privacy Policy

    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.