M
Mark Morton
I'm writing an if statement for a UK credit card form validation
script. Users who specify that their card is Switch need to enter
either the issue number or the 'valid from' date.
I'm trying to write an if statement so that if:
1. The word "Month" is in the validFromMonth field (where they haven't
selected a month a the drop-down menu) or the word "Year" is in the
validFromYear field (where they haven't selected a year another the
drop-down menu)
OR
2. Nothing has been entered in the text box for the Issue_Number
then the alert box appears
<SCRIPT language="text/javascript">
function checkform()
{
if (document.Final.Cardtype.value == "")
{
alert("Please specify the type of debit or credit card.");
return false;
}
if (document.Final.Cardholder.value == "")
{
alert("Please enter the Cardholder's Name.");
return false;
}
if (document.Final.Cardnumber.value == "")
{
alert("Please enter the card number.");
return false;
}
//check whether they need to supply an issue number/start date
var cc_type = document.Final.Cardtype.options[document.Final.Cardtype.selectedIndex].value;
if (cc_type == "Switch")
{
// if card is Switch then we need an issue number or start date
var IssNum = document.Final.Issue_Number.value
var fromM = document.Final.validFromMonth.value
var fromY = document.Final.validFromYear.value
if ((IssNum == "") || ((fromM == "Month") || (fromY == "Year")))
{
alert("You must supply an issue number or a 'Valid From' date for
Switch");
return false;
}
}
// if we reach this point then we submit the form.
return true;
}
//-->
</script>
By enclosing (fromM == "Month") || (fromY == "Year") in their own
brackets, I was hoping it would evaluate that first but it doesn't
seem to be working. The form wants a correct entry in all three before
allowing progress.
[I know I haven't written the checking bit for the expiry date yet,
I'm doing it in order!]
Any ideas?
script. Users who specify that their card is Switch need to enter
either the issue number or the 'valid from' date.
I'm trying to write an if statement so that if:
1. The word "Month" is in the validFromMonth field (where they haven't
selected a month a the drop-down menu) or the word "Year" is in the
validFromYear field (where they haven't selected a year another the
drop-down menu)
OR
2. Nothing has been entered in the text box for the Issue_Number
then the alert box appears
<SCRIPT language="text/javascript">
function checkform()
{
if (document.Final.Cardtype.value == "")
{
alert("Please specify the type of debit or credit card.");
return false;
}
if (document.Final.Cardholder.value == "")
{
alert("Please enter the Cardholder's Name.");
return false;
}
if (document.Final.Cardnumber.value == "")
{
alert("Please enter the card number.");
return false;
}
//check whether they need to supply an issue number/start date
var cc_type = document.Final.Cardtype.options[document.Final.Cardtype.selectedIndex].value;
if (cc_type == "Switch")
{
// if card is Switch then we need an issue number or start date
var IssNum = document.Final.Issue_Number.value
var fromM = document.Final.validFromMonth.value
var fromY = document.Final.validFromYear.value
if ((IssNum == "") || ((fromM == "Month") || (fromY == "Year")))
{
alert("You must supply an issue number or a 'Valid From' date for
Switch");
return false;
}
}
// if we reach this point then we submit the form.
return true;
}
//-->
</script>
By enclosing (fromM == "Month") || (fromY == "Year") in their own
brackets, I was hoping it would evaluate that first but it doesn't
seem to be working. The form wants a correct entry in all three before
allowing progress.
[I know I haven't written the checking bit for the expiry date yet,
I'm doing it in order!]
Any ideas?