MuMu
04-10-2006, 01:13 PM
Hi guys! :)
One quick question... how to i go about useing the fallowing 2 scripts in my page:
1. FORM FIELD VALIDATION
<SCRIPT>
function CheckForm( theform )
{
var bMissingFields = false;
var strFields = "";
if( theform.b_first.value.length < 3 ){
bMissingFields = true;
strFields += " * Billing Information: First Name\n";
}
if( theform.b_last.value.length < 3 ){
bMissingFields = true;
strFields += " * Billing Information: Last Name\n";
}
if( theform.b_addr.value.length < 5 ){
bMissingFields = true;
strFields += " * Billing Information: Address\n";
}
if( theform.b_city.value == '' ){
bMissingFields = true;
strFields += " * Billing Information: City\n";
}
if( theform.b_state.value.length != 2 ){ // State should be a 2 letter code
bMissingFields = true; // If you want to use full state names then pls change != 2 into <5
strFields += " * Billing Information: State\n";
}
if( theform.b_zip.value.length != 5 ){ // validate postalcode - invalid if entry is <> 6
bMissingFields = true;
strFields += " * Billing Information: Zip Code\n";
}
if( theform.b_phone.value.length < 3 ){
bMissingFields = true;
strFields += " * Billing Information: Phone number\n";
}
if( theform.b_email.value.search("@") == -1 || theform.b_email.value.search("[.*]") == -1 ){ // validate email
bMissingFields = true;
strFields += " * Billing Information: E-mail address\n";
}
if( bMissingFields ) {
alert( "I'm sorry, but you must provide the following field(s) before continuing:\n\n" + strFields +"\nPlease complete the missing or invalid fields in the order form\nand click the Submit button to process the order." );
return false;
}
// The SetCookie will empty the cart after the form has been send to your checkout processing scipt (PHP/PL).
// If a user returns to the shop AFTER checkout, the cart will have no items in it.
return true;
}
</SCRIPT>
and...
2. SUBMIT ONCE...
<SCRIPT>
function OnlyOnce( theform )
{
if (document.all || document.getElementById) {
for (i = 0; i < theform.length; i++) {
var tempobj = theform.elements[i];
if (tempobj.type.toLowerCase() == "submit" || tempobj.type.toLowerCase() == "reset")
tempobj.disabled = true;
}
return true;
}
else {
return true;
}
}
</SCRIPT>
The real question is... WHAT WILL MY EVENT HANDLER LOOK LIKE ex.: <form action="checkoutmail.php" method="POST" onSubmit="return OnlyOnce(this);" ?????????>
Your help is higly apreciated.
Thanks!
One quick question... how to i go about useing the fallowing 2 scripts in my page:
1. FORM FIELD VALIDATION
<SCRIPT>
function CheckForm( theform )
{
var bMissingFields = false;
var strFields = "";
if( theform.b_first.value.length < 3 ){
bMissingFields = true;
strFields += " * Billing Information: First Name\n";
}
if( theform.b_last.value.length < 3 ){
bMissingFields = true;
strFields += " * Billing Information: Last Name\n";
}
if( theform.b_addr.value.length < 5 ){
bMissingFields = true;
strFields += " * Billing Information: Address\n";
}
if( theform.b_city.value == '' ){
bMissingFields = true;
strFields += " * Billing Information: City\n";
}
if( theform.b_state.value.length != 2 ){ // State should be a 2 letter code
bMissingFields = true; // If you want to use full state names then pls change != 2 into <5
strFields += " * Billing Information: State\n";
}
if( theform.b_zip.value.length != 5 ){ // validate postalcode - invalid if entry is <> 6
bMissingFields = true;
strFields += " * Billing Information: Zip Code\n";
}
if( theform.b_phone.value.length < 3 ){
bMissingFields = true;
strFields += " * Billing Information: Phone number\n";
}
if( theform.b_email.value.search("@") == -1 || theform.b_email.value.search("[.*]") == -1 ){ // validate email
bMissingFields = true;
strFields += " * Billing Information: E-mail address\n";
}
if( bMissingFields ) {
alert( "I'm sorry, but you must provide the following field(s) before continuing:\n\n" + strFields +"\nPlease complete the missing or invalid fields in the order form\nand click the Submit button to process the order." );
return false;
}
// The SetCookie will empty the cart after the form has been send to your checkout processing scipt (PHP/PL).
// If a user returns to the shop AFTER checkout, the cart will have no items in it.
return true;
}
</SCRIPT>
and...
2. SUBMIT ONCE...
<SCRIPT>
function OnlyOnce( theform )
{
if (document.all || document.getElementById) {
for (i = 0; i < theform.length; i++) {
var tempobj = theform.elements[i];
if (tempobj.type.toLowerCase() == "submit" || tempobj.type.toLowerCase() == "reset")
tempobj.disabled = true;
}
return true;
}
else {
return true;
}
}
</SCRIPT>
The real question is... WHAT WILL MY EVENT HANDLER LOOK LIKE ex.: <form action="checkoutmail.php" method="POST" onSubmit="return OnlyOnce(this);" ?????????>
Your help is higly apreciated.
Thanks!