Anyhow, now that I'm home, here's a JS example I've found useful. It's from Jeremy Keith's DOM Scripting book.
Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Placeholder text</title>
<script type="text/javascript" >
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
oldonload();
func();
}
}
}
function resetFields(whichform) {
for (var i=0; i<whichform.elements.length; i++) {
var element = whichform.elements[i];
if (element.type == "submit") continue;
if (!element.defaultValue) continue;
element.onfocus = function() {
if (this.value == this.defaultValue) {
this.value = "";
}
}
element.onblur = function() {
if (this.value == "") {
this.value = this.defaultValue;
}
}
}
}
function prepareForms() {
for (var i=0; i<document.forms.length; i++) {
var thisform = document.forms[i];
resetFields(thisform);
thisform.onsubmit = function() {
return validateForm(this);
}
}
}
addLoadEvent(prepareForms);
</script>
</head>
<body>
<form method="post" action="">
<label for="name">Name</label><br>
<input name="name" type="text" id="name" value="Name"><br>
<label for="email">Email Address</label><br>
<input name="email" type="text" id="email" value="Email"><br>
<label for="phone">Telephone</label><br>
<input name="phone" type="text" id="phone" value="Telephone"><br>
<input type="submit" name="submitted" value="Send">
</form>
</body>
</html>
Bookmarks