Onclick remove deafult data or value from input box


By using the OnClick event on a text box element we can remove the default text from a input box. Say in Facebook login area you will see email and password input box. By default you will see email text in a input box. Whenever you click on it, it just vanishes and give you the chance to write your email address there.

We will add an OnClick event on the input and then by calling a different function we will make this thing happen

Here is the code.

<form name=form1 method=post action=’test.php’>
<b>Type</b><input type=text name=type value=”Enter your user id ” onclick=”document.form1.type.value =””;”>Enter User ID
<input type=submit value=Submit> </form>

We can integrate a function with the OnClick event of the text box. Here is the code

<html><head><title>(Type a title for your page here)</title>

<script type=”text/javascript”>
function make_blank()
{
document.form1.type.value =””;
}
</script>

</head>
<body >

<form name=form1 method=post action=’test.php’>
<b>Type</b><input type=text name=type value=’Enter your user id’ onclick=”make_blank();”>Enter User ID
<input type=submit value=Submit> </form>

</body>
</html>


Leave a Reply