Hide default text in a field - Javascript? -


i want when click on field, default text hidden , when enter text , click again same field text not hide it.

i tried code doesn't work

javascript code:

for(var = 0; < inputs.length; i++) {     inputs[i].onfocus = function() {         if(typeof value1 != undefined) {              this.value = value1;          }else {             value = this.value;             this.value = '';             this.style.color = "#000";         }     }      inputs[i].onblur = function() {             if(this.value == '' || this.value == value) {                 this.value = value;                 this.style.color = "#707070";             }else {                 value1 = this.value;             }         }     } } 

are looking placeholder attribute?

<input type="text" name="fname" placeholder="first name"> 

if not want html 5, have simulate of course. have add class flag "state" of input field , test on that.

<input id="fname" type="text" value="enter first name" /> <input id="lname" type="text" value="enter last name" />  $("input[type='text']").each(function () {     $(this).focus(function () {         if ($(this).hasclass("has-input")) {             $(this).val($(this).val());         } else {             $(this).val("");         }     })      $(this).blur(function () {         if ($(this).val() !== '') {             $(this).addclass('has-input');         } else {             $(this).removeclass('has-input');         }         if (!$(this).hasclass('has-input')) {             $(this).val($(this).attr('value'));         }     })  }); 

check out fiddle: http://jsfiddle.net/djwave28/sq7v3/3/


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -