The error text should be positioned absolute to a relative parent element.
This is with a mouseover, but the principle is the same:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript">
function showHide(obj) {
var span=obj.parentNode.lastChild;
span.className=(span.className=='error')? 'show' : 'error';
}
window.onload=function() {
var aInput=document.getElementsByTagName('input');
for(var i=0; i<aInput.length; i++) {
aInput[i].onmouseover=aInput[i].onmouseout=function() {showHide(this);};
}
};
</script>
<style type="text/css">
label {position:relative; display:block; margin:1em 0;}
.error {display:none;}
.show {position:absolute; z-index:999; display:block; background:#eee; color:#f00; font-style:italic;}
</style>
</head>
<body>
<form action="#" name="form1">
<div>
<label>Your name:<input type="text"><span class="error">Please enter your name</span></label>
<label>Your code:<input type="text"><span class="error">Please enter your code</span></label>
</div>
</form>
</body>
</html>
At least 98% of internet users' DNA is identical to that of chimpanzees
Bookmarks