What you need is something like the following:
<html>
<head><title>Example</title>
<script>
function validate ()
{
var fname = document.myForm.fname.value;
if (fname == "")
{
alert("Please Fill In Your First Name");
return false;
}
}
</scritpt>
</head>
<body>
<form name = "myForm" onSubmit = "return validate(this);">
<input type="text" size="20" maxlength="20" name="fname">
</form>
</body>
</html>
In the onSubmit part the "this" is a must. validate can be changed to anything.
Hope that helps!