php - How to operate with onfocus? -


I have a textbox.

Now when the page is opened, I get the default value of the text box. Once he clicks on the text box, the value disappears, and then when he removes his cursor from the text box, the old value should be returned.

So how do I do this?

All text boxes on that page Add a specific category to which you want to get this functionality.

  window.onload = function () {var elements = document.querySelectorAll ('.ourClassName'); For (var i = 0, j = elements.length; i & lt; j; i ++) {var element = element [i]; Element.onfocus = function () {this.value = ''; This.style.color = 'black'; }; Element.onblur = function () {if (this.value == '') {this.value = this.getAttribute ('defaultValue'); This.style.color = 'Gray'; }}; Element.onblur (); }};  

Work example:


Comments