Wednesday, 18 September 2013

to show error message beside textbox in javascript

to show error message beside textbox in javascript

Please correct the below code it is not working as expected i.e, i need a
error message to be shown just beside the textfield in the form when user
enters an invalid name Also i need help on validation methods for this
code?
<style type="text/css">
.container {
margin:auto;
width:30%;
}
body {
background: url(1.jpg) no-repeat;
background-size: 100%;
}
</style>
<script type="text/javascript">
function LockName(){
if(locker.lock.value.length==0)
document.getElementById('errfn').innerHTML="this is invalid name";
}
</script>
<div class="container">
<h1>Welcome to Locker</h1>
<form name="locker" action="" onsubmit="return Validateform()"
method="post">
<table>
<tr>
<td align="right"><h1>Lock name:</h1></td>
<td align="left"><h1><input type="text" maxlength="8" name="lock"
onblur="LockName()" ><div id="errfn"> </div>
</h1></td>
</tr><br>
<tr>
<td align="right"><h1>Key:</h1></td>
<td align="left"><h1><input type="text" ></h1></td>
</tr><br>
<tr>
<td align="right"></td>
<td align="left"><input type="submit" value="Submit"></td>
</tr><br>
</table>
</form> <br/>
</head>
<body>
</body>
</html>

No comments:

Post a Comment