Reputation: 4617
i have form that has multiple input text boxes, Which has got some text message in light color. When User Types something That text should Become Dark. I got a jquery code which is working, but i cannot use that for multiple text boxes
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.2.js"></script>
<style>
input{color:grey}
</style>
</head>
<body>
<div class="formWrapper">
<form name=form>
<Input type="text" name="name1" value="Eg : Flat-27,Block 4,Skyline" size="30">
</form>
</div>
<script>
$('input').focus(function(){
if($(this).val() == this.defaultValue){$(this).val('');$(this).css("color","Red");}
}).blur(function(){
if($(this).val() == ''){$(this).val(this.defaultValue);$(this).css("color","grey");}
});
</script>
</body>
</html>
Upvotes: 2
Views: 4929
Reputation: 353
Something along these lines should work:
// jQuery
$("input[type='text']").keyup(function(){
if ($(this).val() !== ''){
$(this).css('color', '#ff0000')
} else {
$(this).css('color', '#000000')
}
});
Upvotes: 3