PDA

View Full Version : text box description



ankush
02-03-2012, 01:21 PM
<html>
<head>
<title>txtbox</title>
<script type="text/javascript">
function blank(a)
{
if(a.value == a.defaultValue) a.value = "";
}
function fill(a)
{
if(a.value == "") a.value = a.defaultValue;
}
</script>
</head>
<body>
<form name="em" action="#" method="post">
<input type="text" value="Enter your email" onfocus="blank(this)" onblur="fill(this)" />
</form>
</body>
</html>


i want to blank textbox on focus and then again fill the default value on blur, this code is working fine but that default text in the textbox is of same color which when we write something in the textbox, i want the default text should be of different color like #CCC and when we insert text it should be of #000 color, i tried define the text color of textbox but then both text color are showing same, any help

vwphillips
02-03-2012, 03:10 PM
<html>
<head>
<title>txtbox</title>
<script type="text/javascript">

function blank(a){
if(a.value == a.defaultValue){
a.value = "";
a.style.color='green';
}
}

function fill(a){
if(a.value == ""){
a.value = a.defaultValue;
a.style.color='red';
}
}

</script>
</head>
<body>
<form name="em" action="#" method="post">
<input type="text" value="Enter your email" onfocus="blank(this)" onblur="fill(this)" />
</form>
</body>
</html>

ankush
02-04-2012, 04:49 AM
thanks that's what i want...onLoad color was black but i fixed it..
thanks for your help