In Association with Amazon.in   Flipkart

Tuesday, November 19, 2013

JavaScript OnFocus Event Example

JavaScript OnFocus Event:  When Control Jumps on the current object then onFocus event function called automatically.

Example:

<html>
<head>
<script>
function f1(str)
{
document.getElementById(str).value ="";
document.getElementById(str).style.backgroundColor="yellow";
document.getElementById(str).style.color="green";
}
</script>
</head>

<body>
<form>
User Name:<input type="text" name="uname" id="un" placeholder="Enter User Name" onFocus="f1('un');">
<br>
Password: <input type="text" name="pwd" id="pw" placeholder="Enter Password" onFocus="f1('pw'); this.type='password';">
<input type="button" value="Show Password" onClick="document.getElementById('pw').type='text'" />
</form>
</body>
</html>

Output:

User Name:
Password:

No comments:

Post a Comment


Related Posts Plugin for WordPress, Blogger...