Friday, September 2, 2011

Javascript to show message below the textbox


Demo:


Name




Source Code:
<html>
<head>
<Title>Javascript to show error message by text in a webpage</title>
<script type="text/javascript" language="javascript">
function check()
{
var a=document.getElementById('txtname').value;
if(a=="")
{
document.getElementById('divMsg').innerHTML="Name can not be Blank";
document.getElementById('divMsg').style.color="red";
}
else
{
document.getElementById('divMsg').innerHTML="Your Name: Mr. " + a;
document.getElementById('divMsg').style.color="green";
}
}
</script>
</head>
<body>
Name <input type="text" id="txtname">
<div id="divMsg"></div>
<input type="submit" onclick="check()" value="click">
</body>
</html>

No comments:

Post a Comment