How to remove default value of input on focus?

$(document). Ready(function(){ var Input = $('inputname=kp1_description'); var default_value = Input.val(); Input. Focus(function() { if(Input.val() == default_value) Input.

Val(""); }). Blur(function(){ if(Input.val(). Length == 0) Input.

Val(default_value); }); })​ That should do it Updated, Forgot that focus does not have a 2nd parameter for the focus-out event because there is none, it has to be chained with blur: http://jsfiddle.net/hDCsZ you should also think about creating your own function for this such as: $.fn. ToggleInputValue = function(){ return $(this). Each(function(){ var Input = $(this); var default_value = Input.val(); Input.

Focus(function() { if(Input.val() == default_value) Input. Val(""); }). Blur(function(){ if(Input.val().

Length == 0) Input. Val(default_value); }); }); } Then use like so $(document). Ready(function(){ $('input').

ToggleInputValue(); })​.

$(document). Ready(function(){ var Input = $('inputname=kp1_description'); var default_value = Input.val(); Input. Focus(function() { if(Input.val() == default_value) Input.

Val(""); }). Blur(function(){ if(Input.val(). Length == 0) Input.

Val(default_value); }); })​ That should do it. Updated, Forgot that focus does not have a 2nd parameter for the focus-out event because there is none, it has to be chained with blur: http://jsfiddle.net/hDCsZ/ you should also think about creating your own function for this such as: $.fn. ToggleInputValue = function(){ return $(this).

Each(function(){ var Input = $(this); var default_value = Input.val(); Input. Focus(function() { if(Input.val() == default_value) Input. Val(""); }).

Blur(function(){ if(Input.val(). Length == 0) Input. Val(default_value); }); }); } Then use like so $(document).

Ready(function(){ $('input'). ToggleInputValue(); })​.

The value doesn't reappaear if nothing has been entered.hmm.. – user342391 Sep 27 '10 at 17:40 Updated, Let me know if that works. – RobertPitt Sep 27 '10 at 17:43 weird still nothing – user342391 Sep 27 '10 at 17:46 Updated again, sorry im half asleep :) – RobertPitt Sep 27 '10 at 17:57.

Don't do it this way. Use a jQuery watermark script: code.google.com/p/jquery-watermark/ $("inputname='kp1_description'"). Watermark("Enter Keypress Description"); There are a lot of things you have to account for if you do it manually.

For instance, what happens when the text box loses focus? If there's no value, you'd want to readd your helper text. If there is, you'd want to honor those changes.

Just easier to let other people do the heavy lifting :).

But using a whole library for a simple task is not the best idea. – RobertPitt Sep 27 '10 at 17:29 True, I'm just of the opinion that this wheel doesn't need to be reinvented. There are lots of scenarios you have to consider and using the library can simplify that a lot.

He tagged his question with jQuery so using a jQuery plugin is probably the most pragmatic way to accomplish this task. – clifgriffin Sep 27 '10 at 17:33 +1 for code reuse. Some problems are hard and should be solved by a library and not reimplemented badly by every code monkey on the planet.

People are especially bad about this when it comes to javascript. – Sorpigal Sep 27 '10 at 18:00.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions