Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

please check why it's not working

Status
Not open for further replies.

KatherineF

Technical User
Mar 3, 2003
124
US
var valid = "0123456789-";
var hyphencount = 0;
var zipcode_fields = new Array(2);
zipcode_fields[0] = document.form.fld_ZipCode.value;
zipcode_fields[1] = document.form.fld_ServiceZipCode.value;

for (var j=0; j < zipcode_fields.length; j++)

temp = "" + zipcode_fields.substring(j, j+1);
if (temp == "-") hyphencount++;
if (valid.indexOf(temp) == "-1") {
alert("Invalid characters in your zip code. Please try again.");
event.returnValue = false;
}
 
I don't see where you have set the subscript i. It should be 0 and/or 1.


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
if ((document.form.fld_ServiceClass.value=='') && (document.form.fld_OfferCode.value=='')) {
alert('Either Offer Code or Service Class has to be filled in!');
event.returnValue = false;
}
// ZipCode Check
var valid = "0123456789-";
var hyphencount = 0;
var zipcode_fields = new Array(2);
zipcode_fields[0] = document.form.fld_ZipCode.value;
zipcode_fields[1] = document.form.fld_ServiceZipCode.value;

for (var i=0; i < zipcode_fields.length; i++)

if (zipcode_fields.length!=5 && zipcode_fields.length!=10) {
alert("Please enter your 5 digit or 5 digit+4 zip code.");
event.returnValue = false;
}
// this part is not working
for (var j=0; j < zipcode_fields.length; j++)

temp = "" + zipcode_fields.substring(j, j+1);
if (temp == "-") hyphencount++;
if (valid.indexOf(temp) == "-1") {
alert("Invalid characters in your zip code. Please try again.");
event.returnValue = false;
}

if ((hyphencount > 1) || ((zipcode_fields.length==10) && ""+zipcode_fields.charAt(5)!="-")) {
alert("The hyphen character should be used with a properly formatted 5 digit+four zip code, like '12345-6789'. Please try again.");
event.returnValue = false;
}
 
var valid = "0123456789-";
var hyphencount = 0;
var zipcode_fields = new Array(2);
zipcode_fields[0] = document.form.fld_ZipCode.value;
zipcode_fields[1] = document.form.fld_ServiceZipCode.value;

for (var i=0; i < zipcode_fields.length; i++)

if (zipcode_fields.length!=5 && zipcode_fields.length!=10) {
alert("Please enter your 5 digit or 5 digit+4 zip code.");
event.returnValue = false;
}
// this part is not working
for (var j=0; j < zipcode_fields.length; j++)

temp = "" + zipcode_fields.substring(j, j+1);
if (temp == "-") hyphencount++;
if (valid.indexOf(temp) == "-1") {
alert("Invalid characters in your zip code. Please try again.");
event.returnValue = false;
}

if ((hyphencount > 1) || ((zipcode_fields.length==10) && ""+zipcode_fields.charAt(5)!="-")) {
alert("The hyphen character should be used with a properly formatted 5 digit+four zip code, like '12345-6789'. Please try again.");
event.returnValue = false;
}
 
You have unbalanced parens in this line:
Code:
if ((hyphencount > 1) || ((zipcode_fields[i].length==10) && ""+zipcode_fields[i].charAt(5)!="-")) {


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
I think something wrong with this part:

zipcode_fields.length

is this a correct way to access array elements' length??
 
I don't need a number of elements in an array, I need an element's length in that array
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top