Do not use on any
shared computer
September 8, 2008 03:36am pdt
 
[x]
Attachment Details

Form Validator Producing Errors ('null' is ull or not an object" and "object doesn't support this property or method")

Zone: JavaScript
Tags: JavaScript, IE6, IE7, Firefox 2.0
I have several problems with this script. It is a great script, so I would like to make it work.

IE6 and IE7:
The email  validation works.
The password validation does not work. The value is being captured as "null", so I get the error: "'null' is ull or not an object. Which also causes an error when I try to see if the passwords match.
The phone validation does not work. When I enter the phone number is correct or incorrect format, I get the error: "object does not support this property or method."

Firefox 2.0:
The email validation gives me my generated error message, whether the email address entered is correct or not.
The password validation does not work: I get error "reference to undefined property strng.length" also "targetdiv has no properties"
The phone validation does not work: I get error "strng.replace is not a function"

Can someone please help me with these errors??
The javascript is first and the form html is second.
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:
function checkEmail (strng) {
var email = document.create_account.email.value;
var error = "";
	if (strng == "") {
	   error = "You didn't enter an email address.\n";
	}
 
var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) { 
       error = "Please enter a valid email address.\n";
    } else {
//test email for illegal characters
       var illegalChars = /[\(\)\<\>\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) {
          error = "The email address contains illegal characters.\n";
       }
    }
inlineMsg('email',error,3);
return false;  
}
 
// phone number - strip out delimiters and check for 10 digits
function checkPhone (strng) {
var phonenum = document.create_account.phone.value;
var error = "";
	if (strng == "") {
	   error = "You didn't enter a phone number.\n";
	}
 
var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
    if (isNaN(parseInt(stripped))) {
		error = "The phone number contains illegal characters.";
    }
    if (!(stripped.length == 10)) {
		error = "The phone number is the wrong length. Make sure you included an area code.\n";
    } 
inlineMsg('phonenum',error,3);
return false;    
}
 
// password - between 6-8 chars, lowercase, and numeral
function checkPassword (strng) {
var pass = document.create_account.password.value;
var error = "";
	if (strng == "") {
		error = "You didn't enter a password.\n";
	}
var illegalChars = /[\W_]/; // allow only letters and numbers
	if (strng.length <= 6) {
		error = "The password must contain at least 6 characters.\n";
	}
	else if (illegalChars.test(strng)) {
		error = "The password contains illegal characters.\n";
	}
inlineMsg('pass',error,3);
return false;    
}    
 
//function samePassword (strng) {
//var passw2 = document.create_account.pass2.value;
//	if (strng != document.create_account.password.value) {
//       error = "The password does not match.\n";
//	}
//inlineMsg('passw2',error,3);
//return false;    
//}  
 
var MSGTIMER = 20;
var MSGSPEED = 5;
var MSGOFFSET = 3;
var MSGHIDE = 3;
 
// build out the divs, set attributes and call the fade function //
function inlineMsg(target,string,autohide) {
  var msg;
  var msgcontent;
  if(!document.getElementById('msg')) {
    msg = document.createElement('div');
    msg.id = 'msg';
    msgcontent = document.createElement('div');
    msgcontent.id = 'msgcontent';
    document.body.appendChild(msg);
    msg.appendChild(msgcontent);
    msg.style.filter = 'alpha(opacity=0)';
    msg.style.opacity = 0;
    msg.alpha = 0;
  } else {
    msg = document.getElementById('msg');
    msgcontent = document.getElementById('msgcontent');
  }
  msgcontent.innerHTML = string;
  msg.style.display = 'block';
  var msgheight = msg.offsetHeight;
  var targetdiv = document.getElementById(target);
  targetdiv.select();
  var targetheight = targetdiv.offsetHeight;
  var targetwidth = targetdiv.offsetWidth;
  var topposition = topPosition(targetdiv) - ((msgheight - targetheight) / 2);
  var leftposition = leftPosition(targetdiv) + targetwidth + MSGOFFSET;
  msg.style.top = topposition + 'px';
  msg.style.left = leftposition + 'px';
  clearInterval(msg.timer);
  msg.timer = setInterval("fadeMsg(1)", MSGTIMER);
  if(!autohide) {
    autohide = MSGHIDE;  
  }
  window.setTimeout("hideMsg()", (autohide * 1000));
}
 
// hide the form alert //
function hideMsg(msg) {
  var msg = document.getElementById('msg');
  if(!msg.timer) {
    msg.timer = setInterval("fadeMsg(0)", MSGTIMER);
  }
}
 
// face the message box //
function fadeMsg(flag) {
  if(flag == null) {
    flag = 1;
  }
  var msg = document.getElementById('msg');
  var value;
  if(flag == 1) {
    value = msg.alpha + MSGSPEED;
  } else {
    value = msg.alpha - MSGSPEED;
  }
  msg.alpha = value;
  msg.style.opacity = (value / 100);
  msg.style.filter = 'alpha(opacity=' + value + ')';
  if(value >= 99) {
    clearInterval(msg.timer);
    msg.timer = null;
  } else if(value <= 1) {
    msg.style.display = "none";
    clearInterval(msg.timer);
  }
}
 
// calculate the position of the element in relation to the left of the browser //
function leftPosition(target) {
  var left = 0;
  if(target.offsetParent) {
    while(1) {
      left += target.offsetLeft;
      if(!target.offsetParent) {
        break;
      }
      target = target.offsetParent;
    }
  } else if(target.x) {
    left += target.x;
  }
  return left;
}
 
// calculate the position of the element in relation to the top of the browser window //
function topPosition(target) {
  var top = 0;
  if(target.offsetParent) {
    while(1) {
      top += target.offsetTop;
      if(!target.offsetParent) {
        break;
      }
      target = target.offsetParent;
    }
  } else if(target.y) {
    top += target.y;
  }
  return top;
}
 
// preload the arrow //
if(document.images) {
//  arrow = new Image(7,80); 
  arrow.src = "../image/misc_list_type_style.png"; 
}
 
 
 
<form name="create_account">
 <ul>
  <li class="account_info_label">
	<div class="account_info_personal">Email Address: <input id="email" name="email" value="" type="text" onchange="checkEmail(this);this.blur();this.focus()" /></div>
	<div class="account_info_privacy"><a href="index.php?module=privacy" target="_blank">Privacy Policy</a></div>
  </li>
  <br clear="all" />
  <li class="account_info_label">
	<div class="account_info_personal">Choose Password: <input id="password" name="password" value="" type="password" onchange="checkPassword(this);this.blur();this.focus()" /></div>
	<div class="account_info_personal_right">Re-Enter Password: <input id="password2" name="password2" value="" type="password" onchange="samePassword(this);this.blur();this.focus()" /></div>
  <br clear="all" />
	<span class="account_info_optional">Password must be at least 6 characters.</span>
  </li>
  <br clear="all" />
  <li class="account_info_label">
	<div class="account_info_personal">Phone Number: <input id="phone" name="phone" value="" type="text" onchange="checkPhone(this);this.blur();this.focus()" /></div>
	<div class="account_info_personal_right">Fax Number: <span class="account_info_optional">(optional)</span> <input id="fax" name="fax" value="" type="text" /></div>
  </li>
</ul>
</form>
Start your free trial to view this solution
[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!

Question Stats
Zone: Programming
Question Asked By: dessin
Solution Provided By: hielo
Participating Experts: 1
Solution Grade: A
Views: 8
Translate:
Loading Advertisement...
 
[+][-]Expert Comment by hielo

Rank: Genius

Expert Comment by hielo:

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.

 
 
[+][-]Author Comment by dessin
Author Comment by dessin:

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.

 
 
[+][-]Expert Comment by hielo

Rank: Genius

Expert Comment by hielo:

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.

 
 
[+][-]Author Comment by dessin
Author Comment by dessin:

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.

 
 
[+][-]Author Comment by dessin
Author Comment by dessin:

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.

 
 
[+][-]Accepted Solution by hielo

Rank: Genius

Accepted Solution by hielo:

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.

 
 
[+][-]Author Comment by dessin
Author Comment by dessin:

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...
20080723-EE-VQP-34 / EE_QW_2_20070628