Default value by using OnFocus event of a text box
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.
<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>