i got a problem with my Order form. I need to validate some of the fields, checkboxs, dropdown list, and the quantity of the products. So i just started with the checkbox. It have to looks like: If i check the box, but not specify the quantity of the product, its popup a javascript alert that tell me to specify how much i want to order from that product. And if i dont check the checkbox its start alert me with that. Second, i need to Validate the card number for: Only number and 20 character with - after every 4 digits. Just done with the checkbox validate but cant even done the quantity validate and the card number, card type validate.
<!doctype html>
<html>
<head>
<meta charset="iso-8859-2">
<title>Order</title>
<script language="javascript">
function validateFunction() {
var fo = document.cardform;
if (!fo.field1.checked && !fo.field2.checked && !fo.field3.checked) {
alert("Must choose at least one thing to buy");
return false;
}
return true;
}
</script>
</head>
<body>
<h2>
<strong>
Order
</strong>
</h2>
<form name="cardform" action="" onsubmit="return validateFunction();">
Name: <input type="text" name="name" size="40px" required> </br>
Adress: <input type="text" name="adress" size="40px" required> </br>
Card Type: <select name="card" form="cardform" required>
<option value="choose" selected>Please Choose</option>
<option value="visa">Visa</option>
<option value="americanexpress">American Express</option>
<option value="mastercard">Master Card</option>
<option value="maestro">Maestro</option>
</select>
Cardnumber: <input type="number" name="cardnumber" required> </br>
<table border="1px">
<tr>
<td>
name:
</td>
<td>
price:
</td>
<td>
q:
</td>
</tr>
<tr>
<td>
<input type="checkbox" name="field1">1
</td>
<td>
13
</td>
<td>
<input type="text" name="1q">
</td>
</tr>
<tr>
<td>
<input type="checkbox" name="field2">2
</td>
<td>
133
</td>
<td>
<input type="text" name="2q">
</td>
</tr>
<tr>
<td>
<input type="checkbox" name="field3">3
</td>
<td>
1337
</td>
<td>
<input type="text" name="3q">
</td>
</tr>
</table>
Comment: </br>
<textarea name="comments" cols="25" rows="5"> Comment here </textarea> </br>
<input type="submit" value="Submit">
<input type="reset" value="Reset">
</form>
</body>
</html>