Advertisement

03.04.2008 at 12:56PM PST, ID: 23214033
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

Javascript form validation works in I.e., not safari or firefox

I have an asp.net application where I use a javascript file to validate the form entries (basic bill to ship to info). The .js file utilizes the class object for its tpe validation. I have created clientid's in my code and I create an array of required fields and a companion text map to populate an alert message string. All works well in I.E. In Safari the code stops working once I define the arrays. I am quite stumped. Any help would be appreciated. Code attached, sorry my own comments were not edited out - Please be kind!! This is my bosses account, so please do not hold it against him..

Thanks :)
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
 
// For a more flexible event registration routine, see
 
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    };
  }
}
 
addLoadEvent(attachFormHandlers());
addLoadEvent(function() {
  /* more code to run on page load */ 
 
 
});
function attachFormHandlers()
{
  // Ensure we're working with a 'relatively' standards 
  // compliant browser
  if (document.getElementsByTagName)
  {
 
    var objForm = window.document.getElementsByTagName('form');
    
    //objForm.innerHTML = objForm.innerHTML;
    for (var iCounter=0; iCounter<objForm.length; iCounter++)
      objForm[iCounter].onsubmit = function(){return formCheck(this);};
  }
}
function formCheck(formobj){
 
 
	// Enter name of mandatory fields
    //var fieldRequired = new Array();
   var objForm = window.document.form1.elements;
    
   if (window.document.form1.shipbilltosame.checked)
   {
	    
   //Same Bill To Ship To
	    var country = countryID.options(countryID.selectedIndex).text;
	// COUNTRY United States or Canada
	        if(country == "United States" || country == "Canada")
	        {
	        //state drop down 
	            var state = stateID.options(stateID.selectedIndex).text;
	            if (state == "- Canadian Provinces -" || state == "- US States -" || state == "Select State / Province")
	            {
	            alert ("Please select from the Bill To State Drop Down");
	            return false;
	    
	            }
    //alert ("hey " + country);
	            //var fieldRequired = Array(firstnameID.id, lastnameID.id, address1ID.id, cityID.id, stateID.id, zipID.id, email_addressID.id, phoneID.id, countryID.id);
	            var fieldRequired = [firstnameID.id, lastnameID.id, address1ID.id, cityID.id, stateID.id, zipID.id, email_addressID.id, phoneID.id, countryID.id];
	// Enter field description to appear in the dialog box
	            var fieldDescription = ["First Name", "Bill To Last Name", "Bill To First Address Line", "Bill To City", "Bill To State", "Bill To Zip", "Email Address is either blank or not valid", "Bill To Phone", "Bill To Country"];
	        }
	// COUNTRY NOT United States or Canada
	        else
	        {
	            var fieldRequired = [firstnameID.id, lastnameID.id, address1ID.id, email_addressID.id, phoneID.id, countryID.id];
	// Enter field description to appear in the dialog box
	            var fieldDescription = ["Bill To First Name", "Bill To Last Name", "Bill To First Address Line", "Email Address is either blank or not valid", "Bill To Phone", "Bill To Country"];
	//alert ("hey international" + country);
	        }
	// dialog message
	}
	else
	{
   //Different Bill To Ship To
	    //var country = countryID.options(countryID.selectedIndex).text;
	    var shipcountry = ship_countryID.options(ship_countryID.selectedIndex).text;
	     if (shipcountry == "Select Country")
	     {
	    alert ("Please make a selection from the Ship To Country or check the Ship To Same Box");
	    return false;
	    
	    }
	// COUNTRY United States or Canada
	        if (country === "United States" || country === "Canada")
	            {var BC = "dd";}
	        else
	           {var BC = "nd";}
	        
	        if (shipcountry === "United States" || shipcountry === "Canada")
	            {var SC = "dd";}
	        else
	            {var SC = "nd";}
	        //alert ("hey SC "+ SC + "BC " + BC);
	            
	            if (BC === "dd" && SC === "dd")
	                {
    //alert ("hey " + country);
	                var fieldRequired = [firstnameID.id, lastnameID.id, address1ID.id, cityID.id, stateID.id, zipID.id, email_addressID.id, phoneID.id, countryID.id, ship_firstnameID.id, ship_lastnameID.id, ship_address1ID.id, ship_cityID.id, ship_stateID.id, ship_zipID.id, ship_phoneID.id, ship_countryID.id];
	// Enter field description to appear in the dialog box
	                var fieldDescription = ["Bill To First Name", "Bill To Last Name", "Bill To First Address Line", "Bill To City", "Bill To State", "Bill To Zip", "Email Address is either blank or not valid", "Bill To Phone", "Bill To Country", "Ship To First Name", "Ship To Last Name", "Ship To First Address Line", "Ship To City", "Ship To State", "Ship To Zip", "Ship To Phone", "Ship To Country"];
	                }
	                
	// COUNTRY NOT United States or Canada
	            if (BC === "nd" && SC === "nd")
	                {
	                var fieldRequired = [firstnameID.id, lastnameID.id, address1ID.id, email_addressID.id, phoneID.id, countryID.id, ship_firstnameID.id, ship_lastnameID.id, ship_address1ID.id, ship_phoneID.id, ship_countryID.id];
	// Enter field description to appear in the dialog box
	                var fieldDescription = ["Bill To First Name", "Bill To Last Name", "Bill To First Address Line", "Email Address is either blank or not valid", "Bill To Phone", "Bill To Country", "Ship To First Name", "Ship To Last Name", "Ship To First Address Line", "Ship To Phone", "Ship To Country"];
	//alert ("hey international" + country);
	                }
	                
	            if (BC === "dd" && SC === "nd")
	                {
    //alert ("hey " + country);
	                var fieldRequired = [firstnameID.id, lastnameID.id, address1ID.id, cityID.id, stateID.id, zipID.id, email_addressID.id, phoneID.id, countryID.id, ship_firstnameID.id, ship_lastnameID.id, ship_address1ID.id, ship_phoneID.id, ship_countryID.id];
	// Enter field description to appear in the dialog box
	                var fieldDescription = ["Bill To First Name", "Bill To Last Name", "Bill To First Address Line", "Bill To City", "Bill To State", "Bill To Zip", "Email Address is either blank or not valid", "Bill To Phone", "Bill To Country", "Ship To First Name", "Ship To Last Name", "Ship To First Address Line", "Ship To Phone", "Ship To Country"];
	                }
	                
	// COUNTRY NOT United States or Canada
	            if (BC === "nd" && SC === "dd")
	                {
	                var fieldRequired = [firstnameID.id, lastnameID.id, address1ID.id, email_addressID.id, phoneID.id, countryID.id, ship_firstnameID.id, ship_lastnameID.id, ship_address1ID.id, ship_cityID.id, ship_stateID.id, ship_zipID.id, ship_phoneID.id, ship_countryID.id];
	// Enter field description to appear in the dialog box
	                var fieldDescription = ["Bill To First Name", "Bill To Last Name", "Bill To First Address Line", "Email Address is either blank or not valid", "Bill To Phone", "Bill To Country", "Ship To First Name", "Ship To Last Name", "Ship To First Address Line", "Ship To City", "Ship To State", "Ship To Zip", "Ship To Phone", "Ship To Country"];
	
	                }
	                
	// 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 = objForm.elements[fieldRequired[i]];
	
			if (obj){
			switch(obj.className){
			//switch(obj.type){
			//case "select-one":
			case "select-one":
				if (obj.selectedIndex === -1 || obj.options[obj.selectedIndex].value === "" || obj.options[obj.selectedIndex].value === null){
					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;
				case "email":
			//case "email":
				
					var x = obj.value;
	                var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	                if (!filter.test(x)){ //break;//alert('YES! Correct email address');
	                //else alertMsg += " - " + fieldDescription[i] + "\n";
	                alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "numeric":
			    
				if (obj.value === "" || obj.value === null || isNaN(obj.value)){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			default:
			}
			switch(obj.type){
			case "select-one":
				if (obj.selectedIndex === -1 || obj.options[obj.selectedIndex].value === "" || obj.options[obj.selectedIndex].value === null){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
				default:
			}
			//if (obj.type == undefined){
			if (obj.className === 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;
	}
}
 
// -->
Start your free trial to view this solution
Question Stats
Zone: Software
Question Asked By: MulyCat
Solution Provided By: MulyCat
Participating Experts: 2
Solution Grade: A
Views: 92
Translate:
Loading Advertisement...
03.04.2008 at 06:01PM PST, ID: 21047143

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.04.2008 at 08:25PM PST, ID: 21047724

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.06.2008 at 11:26AM PST, ID: 21063771

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.07.2008 at 09:11AM PST, ID: 21072242

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
20080236-EE-VQP-29 / EE_QW_2_20070628