Default value by using OnFocus event of a text box

Text OnFoucs We can trigger any function or perform any task by using onfocus event for the form elements. For example we want to show some text inside a text element when crusher enters into the text box. Here we will use onfocus event. If we are using tab to navigate between the form elements then for each elements of a form we can give some default value.

We have used here three text boxes and by using tab each elements can be accessed. For the third element ( third text box ) we have used the on focus event to trigger the JavaScript function to set the value for the text box.

demo of text onfocus

Here is the code
<html>
<head>
<title>(Type a title for your page here)</title>
<script type="text/javascript">
function entername()
{
document.f1.t1.value="Name";
}
</script>

</head>
<body >

<form name=f1 action='' method=post>
Your Userid<input type=text name=t3><br>
Your Password<input type=text name=t2><br>
Your Name<input type=text name=t1 onfocus='entername()';>
</form>

</body>
</html>
Event Handling onKeyPress Mouse event Textarea onClick event
Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com







    Post your comments , suggestion , error , requirements etc here




    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer