...

View Full Version : javascript form check



lifeisboost
07-09-2011, 10:54 AM
Okay this is part of an ajax driven shopping cart. the problem is i need to check for 2 different selections that would be for the same payment method. here is the code as it sits now


if ( typeof document.checkout.payment[3] != 'undefined'){
if (document.checkout.payment[3].checked == true)
{

if (document.checkout.cc_owner.value == "" )
{errMsg += 'Please complete or verify the information in the Name on the card field in the \'Payment Method\' section.' + "\n";
}
else
{
if(document.checkout.cc_number.value == "")
{
errMsg += 'Please complete or verify the information in the Card Number field in the \'Payment Method\' section.' + "\n";
}
else
{
if(document.checkout.cc_cvv2.value == "")
{
errMsg += 'Please complete or verify the information in the CVC/CVV code field in the \'Payment Method\' section.' + "\n";

}
else
{
if(document.checkout.cc_phone.value == "")
{
errMsg += 'Please complete or verify the information in the Card company\'s telephone number field in the \'Payment Method\' section.' + "\n";

}
else
{
myCardNo = document.checkout.cc_number.value;
myCardType = document.checkout.surcharge.value;
if (!checkCreditCard (myCardNo,myCardType))
{
errMsg += 'Please complete or verify the information in the Card Number field in the \'Payment Method\' section.' + "\n";
}
}
}
}
}
}}
}


the problem is in the first 2 lines i basically need it to do this, but when i do it like how i need it to be it will not work. it looks like i am doing it incorrectly maybe.

firebug gives me an undefined error on the first checked value because it does not exist when i need it to check for the 2 value.


if ( typeof document.checkout.payment[3] != 'undefined' || typeof document.checkout.payment[2] != 'undefined'){
if (document.checkout.payment[3].checked == true || document.checkout.payment[2].checked == true)
{

if (document.checkout.cc_owner.value == "" )
{errMsg += 'Please complete or verify the information in the Name on the card field in the \'Payment Method\' section.' + "\n";
}
else
{
if(document.checkout.cc_number.value == "")
{
errMsg += 'Please complete or verify the information in the Card Number field in the \'Payment Method\' section.' + "\n";
}
else
{
if(document.checkout.cc_cvv2.value == "")
{
errMsg += 'Please complete or verify the information in the CVC/CVV code field in the \'Payment Method\' section.' + "\n";

}
else
{
if(document.checkout.cc_phone.value == "")
{
errMsg += 'Please complete or verify the information in the Card company\'s telephone number field in the \'Payment Method\' section.' + "\n";

}
else
{
myCardNo = document.checkout.cc_number.value;
myCardType = document.checkout.surcharge.value;
if (!checkCreditCard (myCardNo,myCardType))
{
errMsg += 'Please complete or verify the information in the Card Number field in the \'Payment Method\' section.' + "\n";
}
}
}
}
}
}}
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum