First page Back Continue Last page Image

<!DOCTYPE html>

<html>

<head>

<title>Requiring an entry</title>

<link rel="stylesheet" href="script06.css">

<script src="script06.js"></script>

</head>

<body>

<form action="#">

<h3>

Email address: <input type="text" class="reqd"><br><br>

Name (optional): <input type="text">

</h3>

</form>

</body>

</html>

window.onload = initForm;

function initForm() {

var allTags = document.forms[0].getElementsByTagName("*");

for (var i=0; i<allTags.length; i++) {

if (allTags[i].className.indexOf("reqd") > -1) {

allTags[i].onblur = fieldCheck;

}

}

}

function fieldCheck() {

if (this.value == "") {

this.className += " highlight";

this.focus();

}

else {

this.className = "reqd";

}

}

body {

background-color: #FFF;

}

.highlight {

background-color: #FF9;

}

Look at all tags for one with a class of reqd. Only run the next line if you find one

Form Fieldcheck Code