All,
I'm trying to validate using JavaScript some form fields - so that if the Visa or Mastercard radio buttons are clicked - then the card number or expire date must also be filled in - what would be the recommended approach for this:
JavaScript code:
<script type="text/javascript">
function paymentCheck(){
if(document.form1.payment.Visa.checked == true) || (document.form1.payment.Mastercard.checked == true) && (document.form1.card.value == "") || (document.form1.exp.value="") {
alert ("Please enter in a card or expiration number")
form1.card.focus();
return(false);
}
return (true);
}
</script>
HTML code:
<FORM METHOD="post" ACTION="" name="form1">
<TABLE BORDER=0>
<TR VALIGN="top">
<TD ALIGN="right"><FONT SIZE=2><B>Payment Method:</B></FONT></TD>
<TD ALIGN="left">
<INPUT NAME="payment" TYPE="radio" VALUE="Visa">Visa<BR>
<INPUT NAME="payment" TYPE="radio" VALUE="Mastercard">Mastercard<BR>
<INPUT NAME="payment" TYPE="radio" VALUE="Check">Personal Check<BR>
</TD>
</TR>
<TR VALIGN=:top">
<TD ALIGN="right"><FONT SIZE=2><B>Card Number/Expiration Date:</B></FONT></TD>
<TD ALIGN="left"><INPUT NAME="card" SIZE=16>/<INPUT NAME="exp" SIZE=5></TD>
</TR>
<TR VALIGN=:top">
<TD ALIGN="right"><FONT SIZE=2><B>Card Code Number:</B></FONT></TD>
<TD ALIGN="left"><INPUT NAME="cardcode" SIZE=5></TD>
</TR>
<TR VALIGN=TOP>
<TD ALIGN=RIGHT><INPUT TYPE="reset" VALUE="Reset"></TD>
<TD ALIGN=LEFT><INPUT TYPE="submit" VALUE="Complete Order" onclick="paymentCheck()"></TD>
</TR>
</TABLE>
</FORM>