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:
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:
No comments:
Post a Comment