Forum Moderators: open
Tested against the W3C validator.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- doctype on one line -->
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
<title>XML Form Test</title>
<script type="text/javascript">
function validate(form) {
var msg = '';
if (document.getElementById('txt').value=='') { msg = 'Fill in the field.'; }
if (msg != '') { alert(msg); }
else { form.submit(); }
return false;
}
window.onload=function () {
if (document.getElementById) {
document.getElementById('test-form').onsubmit = function() {
return validate(document.getElementById('test-form'));
}
}
}
</script>
</head>
<body>
<form action="test.cgi" id="test-form" method="post">
<label for="txt">Just enter something:</label>
<input type="text" name="txt" id="txt" size="24" maxlength="100" value=""/>
<input type="submit" value="Submit"/>
</form>
</body>
</html>