<html>
<head>
<title>Form Validation</title>
<script type="text/javascript">
function checkValid() {
var cityField = document.forms[0]["city"];
if (cityField.value != "Van") {
var cityDiv = document.getElementById("citydiv");
cityDiv.style.fontWeight = "bold";
return false;
} else {
return true;
}
}
</script>
</head>
<body>
<form name="formexample" id="formexample" action="#">
<div id="citydiv">City: <input id="city" name="city"></div>
<div><input id="submit" type="submit"></div>
</form>
<script type="text/javascript">
function init() {
document.forms[0].onsubmit = function() { return checkValid(this) };
}
window.onload = init;
</script>
</body>
</html>
|