SQL PHP HTML ASP JavaScript articles and free scripts to download

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.

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>


Google+

Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked




Join Our Email List
Email:  
For Email Newsletters you can trust
HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2014 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer