topical media & game development
basic-web-html-12-ch12-eg07.htm / htm
<html>
<head>
<title>Form validation</title>
<script type="text/JavaScript" language="JavaScript">
function validate(form) {
var radioButtons = form.radSuit;
radioChosen = false;
for (var i=0; i<radioButtons.length; i++) {
if (radioButtons[i].checked)
{
radioChosen=true;
returnValue = true;
}
}
if (radioChosen == false) {
returnValue = false;
alert("You did not select a suit of cards");
}
return returnValue;
}
</script>
</head>
<body>
<form name="frmCards" action="cards.aspx" method="post"
onsubmit="return validate(this)" >
<p>Please select a suit of cards.</p>
<p><input type="radio" name="radSuit" value="hearts" /> Hearts </p>
<p><input type="radio" name="radSuit" value="diamonds" /> Diamonds </p>
<p><input type="radio" name="radSuit" value="spades" /> Spades </p>
<p><input type="radio" name="radSuit" value="clubs" /> Clubs </p>
<p><input type="submit" value="Submit choice" /></p>
</form>
</body>
</html>
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.