This Blog has moved to http://www.falsepositives.com/

False Positives Adventures in Technology, SciFi and Culture from Toronto

Monday, April 28, 2003

JS form validate to re-cycle



function validateForm() {
var f = document.forms[0]
var ErrorFields = ""
var ccError = ""


// For development Only

selectedbypassLoc = f.bypass.selectedIndex
selectedbypassValue = f.bypass.options[selectedbypassLoc].text

if ( selectedbypassValue != "Test" )
{
alert ("For development Only Validation ByPass!!!!")
f.submit()
return("")
}


var i = 0, temp = 0;
var allEmptyFields = "";
var Empty = false;
var emptyFields = new Array();

if ( f.FirstName.value == "" )
{
emptyFields[i] = "First Name";
Empty = true;
i++;
}
if ( f.LastName.value == "" )
{
emptyFields[i] = "Last Name";
Empty = true;
i++;
}
if ( f.Address1.value == "" )
{
emptyFields[i] = "Address";
Empty = true;
i++;
}
if ( f.AddressCity.value == "" )
{
emptyFields[i] = "City";
Empty = true;
i++;
}
selectedProvLoc = f.AddressProvince.selectedIndex
selectedProvValue = f.AddressProvince.options[selectedProvLoc].text
if ( selectedProvValue == "" )
{
emptyFields[i] = "Province";
Empty = true;
i++;

}
if ( f.AddressPostalCode.value == "" )
{
emptyFields[i] = "Postal Code";
Empty = true;
i++;
}
if ( f.PhoneBusiness.value =="" && f.PhoneHome.value =="" )
{
if ( f.PhoneBusiness.value =="" )
{
emptyFields[i] = "Business Phone Number";
Empty = true;
i++;
}
else
{
emptyFields[i] = "Home Phone Number";
Empty = true;
i++;
}
}
if ( f.PhoneHome.value !="" && f.PhoneHomeAreaCode.value == "" )
{
emptyFields[i] = "Home Phone Number Area Code";
Empty = true;
i++;
}
if ( f.PhoneBusiness.value !="" && f.PhoneBusinessAreaCode.value == "" )
{
emptyFields[i] = "Business Phone Number Area Code";
Empty = true;
i++;
}
if ( f.EMail.value == "" )
{
emptyFields[i] = "Email Address";
Empty = true;
i++;
}
selectedCCTLoc = f.CreditCardType.selectedIndex
selectedCCTValue = f.CreditCardType.options[selectedCCTLoc].text
if ( f.selectedCCTValue == "" )
{
emptyFields[i] = "Credit Card Type";
Empty = true;
i++;
}
if ( f.CreditCardName.value == "" )
{
emptyFields[i] = "Credit Card Name";
Empty = true;
i++;
}

if ( f.DSEXPMTH.value == "" || f.DSEXPYEAR.value == "" )
{
emptyFields[i] = "Credit Card Expriy Date";
Empty = true;
i++;
}

if ( f.DSCARD1.value == "" || f.DSCARD2.value == "" || f.DSCARD3.value == "" || f.DSCARD4.value == "" )
{
emptyFields[i] = "Credit Card Number";
Empty = true;
i++;
}
else
{
ccError = validateCard();
}
if (Empty)
{
for(var count = 0; count < i; count++)
{
temp = emptyFields[count].length;
allEmptyFields +=emptyFields[count];
if (count % 2 != 0)
allEmptyFields += "\n";
else
{
if (temp > 38)
allEmptyFields += "\t";
if (temp <=38 && temp >29)
allEmptyFields += "\t\t";
if (temp <= 29 && temp >17)
allEmptyFields += "\t\t\t";
if (temp <= 17 && temp > 8)
allEmptyFields += "\t\t\t\t";
if (temp<=8)
allEmptyFields += "\t\t\t\t\t";
}
}
EmptyFieldsAlert = "\nThe following field(s) must be filled in before the form can be submitted:\n\n" + allEmptyFields + "\n"
}
if ( ccError != "" )
{
EmptyFieldsAlert = EmptyFieldsAlert + "\n\n" + ccError
}
if ( EmptyFieldsAlert != "" )
{
alert(EmptyFieldsAlert )
}
else
{
f.submit()
}
}

Not pretty but it works!.

This is how Jake got started, must be very careful.


Please Note that this Blog (False Positives) has moved to http://www.falsepositives.com/

Links to this post:

Create a Link

<< Home