Nah, we hate 'em too. Who wants to be 'alerted'?
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>untitled</title>
<script type="text/javascript" language="javascript">
var req_fields = ['firstname1' , 'middlename1' , 'surname1'];
function checkform(oForm)
{
for (var field, bad = 0, f = 0; f < req_fields.length; ++f)
{
field = oForm.elements[req_fields[f]];
if (field.value == field.defaultValue || /^\s*$/.test(field.value))
{
field.value = field.defaultValue;
field.style.border = '2px #f00 dashed';
bad = 1;
}
}
if (bad)
return false;
else return true;
}
function restore(oText)
{
oText.style.border = '2px #000 solid';
}
function restoreAll(oForm)
{
for (var field, f = 0; f < req_fields.length; ++f)
{
field = oForm.elements[req_fields[f]];
restore(field);
}
}
</script>
</head>
<body style="margin:100px;">
<form name="theForm" action="javascript:alert('ok')" onsubmit="return checkform(this)" onreset="restoreAll(this)">
<input id="firstname1" name="firstname1" type="text" style="width:156px;padding:2px;border:2px #000 solid;"
value="Please enter a value here."
onclick="if(this.value==this.defaultValue)this.value='';restore(this)"
onkeypress="restore(this)">___first name<br />
<input id="middlename1" name="middlename1" type="text" style="width:156px;padding:2px;border:2px #000 solid;"
value="Please enter a value here."
onclick="if(this.value==this.defaultValue)this.value='';restore(this)"
onkeypress="restore(this)">___middle name<br />
<input id="surname1" name="surname1" type="text" style="width:156px;padding:2px;border:2px #000 solid;"
value="Please enter a value here."
onclick="if(this.value==this.defaultValue)this.value='';restore(this)"
onkeypress="restore(this)">___last name<br /><br />
<input type="submit" value="submit">
<input type="reset" onclick="return confirm('Clear all entries?')">
</form>
</body>
</html>
Bookmarks