Click to See Complete Forum and Search --> : Validation of CC form
celtic5544
10-23-2003, 09:38 AM
Ok I need a javascript for the following. I have 3 radio buttons for a pay page, if someone hits the CC radio button I need for them to fill out the credit card information. But if they do not fill it out and hit the submit button for a box to come up to warn them that they have not filled out the CC information. I am supper new at this so the most detailed help you can give would be wonderful.
Thanks
Charles
10-23-2003, 02:58 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<title>Example</title>
<style type="text/css">
<!--
label {display:block; margin:1em 0em}
-->
</style>
<script type="text/javascript">
<!--
function validate (form) {
for (var i=0; i<form.method.length; i++) {if (form.method[i].value == 'credit') var credit = form.method[i].checked}
if (credit && !/\S/.test(form.number.value)) {alert('Please provide a credit card number.'); form.number.focus(); return false};
}
// -->
</script>
<form action="" onsubmit="return validate(this)">
<div>
<fieldset>
<legend>Method of Payment</legend>
<label><input type="radio" name="method" value="cash">Cash</label>
<label><input type="radio" name="method" value="check">Check</label>
<label><input type="radio" name="method" value="credit">Credit Card</label>
<label>Credit Card Number <input type="text" name="number"></label>
</fieldset>
<button type="submit">Submit</button>
</div>
</form>