Reputation: 694
Hi im building a form where in php i already know the email of the user.. So i insert it as value "in gray" if you select the input with the mouse. it became black "active". but then if you select something else, it became gray again.. obviously cause its not in focus anymore..
but how can i preserve the black color after the user select this for just one time.. so it dosent became gray again. thanks
here is a fiddle http://jsfiddle.net/BAes7/
Here is my code
<input type="text" name="email" id="email" value="[email protected]" size="22" onblur="if(this.value == '[email protected]') { this.style.color='#ccc'; this.value='[email protected]'}" onfocus="if (this.value == '[email protected]') {this.style.color='#000'; this.style.fontStyle='normal'; this.value='[email protected]'}" class="textBox" style="color: rgb(204, 204, 204); font-style: normal;">
Upvotes: 0
Views: 58
Reputation: 5911
Edit: ohh, I thought JS/JQuery was assumed. I used JQuery. Let me see if I can find a straight JS solution for you (if you need it?).
<input id="special_text_box" name="special_text_box" type="text" value="hello world"></input>
<style>
#special_text_box {color:#C0C0C0}
</style>
<script>
$("#special_text_box").on('focusin',function(){
$(this).css('color','#000000');
});
</script>
k... pure JS:
<input type="text" value="hello world" style="color:#C0C0C0"
onfocus="this.style.color='#000000'"></input>
Upvotes: 2