0

Please refer the fiddle http://jsfiddle.net/a765q/1/.

If I click the reset button, the text color turns to grey. How to do?

designersvsoft
  • 1,861
  • 9
  • 39
  • 66

2 Answers2

3

I would suggest using the newer placeholder attribute for this rather than the aproach you're going for.

modified from your fiddle!:

<input name="address" id="address" type="text" placeholder="Address" />

Dale
  • 10,384
  • 21
  • 34
  • 3
    The internet is not supported in IE ;) – Dale Jul 17 '12 at 10:18
  • Let me just say... it very soon will be supported in IE, and people running older version of do not deserve to see such wonders (in my opinion) – Dale Jul 17 '12 at 10:19
  • `if (document.all){alert("You are using a severly incompatible and outdated browser. Get Chrome");}` ;-) – amon Jul 17 '12 at 10:20
  • 1
    @designersvsoft: My answer to this older question is exactly what you should do: http://stackoverflow.com/questions/7433589/input-with-watermark-css-jquery/7433860#7433860. There are polyfills that don't use jQuery if you aren't using it. – thirtydot Jul 17 '12 at 10:20
1

here is working fiddle: http://jsfiddle.net/surendraVsingh/a765q/13/

HTML

<form action="">
    <input name="address" id="address" type="text" value="Address" />
    <input name="reset" type="reset" value="Reset Form">
</form>​

Jquery

 $('#address').focus(function(){
    $(this).val(''); 
    $(this).css('color', '#000'); 

});
$('input[type="reset"]').click(function(){

       $('#address').css('color', '#999'); 
});

SVS
  • 4,245
  • 1
  • 23
  • 28
  • Nope. If you type text into the `input`, and then focus something else, the text turns grey when it shouldn't. – thirtydot Jul 17 '12 at 10:23
  • You are right SVS. But please note my fiddle location. If we type the value in the text field the color turns to grey to black. The text color is not changed on focus or something. Only i click the reset button the color turns to black to grey. – designersvsoft Jul 17 '12 at 10:26
  • @designersvsoft: Sigh. Doing it like this just is not a good idea. As it is now, if someone just presses the submit button I assume is there in the real thing, the "placeholder" value will be submitted. Also jQuery is now being used, so there's no reason not to just follow the advice in my comment on the other answer. – thirtydot Jul 17 '12 at 10:59
  • @designersvsoft You can validate form if you dont want user to accidentally submit default value. – SVS Jul 17 '12 at 11:05
  • I downvoted your answer because you're leading him down the garden path. If he carries on with this approach, he's going to end up with a form broken in many subtle ways, with far more code than is necessary. – thirtydot Jul 17 '12 at 11:14
  • @thirtydot Its just a answer or you can say way of doing what he want. I never said this is the only answer. You downvoted my answer that's your choice. – SVS Jul 17 '12 at 11:20
  • I'm trying to convince you to *delete your answer*, it's that bad. Stack Overflow questions are not just for the person who posted them. Ideally, people who have the same problem in the future would find this question and read it. The demo in your answer, right now: http://jsfiddle.net/surendraVsingh/a765q/13/. Type something in the input box. Click on the white space anywhere else on the page. Oh no, you've just noticed that you made a typo in the input box! Let's go and fix it! Click back into the input box. Oh no, it's now empty. Broken, broken, broken. – thirtydot Jul 17 '12 at 11:29