Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clearing the textbox values onclick and displaying onblur

Tags:

javascript

Is there a way to clear the default textbox value onclick on textbox and display onblur of multiple textboxes on form page?

like image 479
Aayush Aarwal Avatar asked Mar 11 '13 10:03

Aayush Aarwal


People also ask

Does Onblur fires before Onclick?

The divs inside the menu also have onclick() events which execute the special processing. The problem is that the onclick() events never fire when the menu is clicked, because the input field's onblur() fires first and deletes the menu, including the onclick() s!

How do you clear a text box in JavaScript?

You can use the onfocus attribute in JavaScript to clear a textbox or an input box when somebody sets focus on the field. If you are using jQuery, then use the . focus() method to clear the field.


2 Answers

HTML:

<input type="text" value="" onClick="Clear();" id="textbox1>
<input type="text" value="" onClick="Clear();" id="textbox2>
<input type="text" value="" onClick="Clear();" id="textbox3>
<input type="text" value="" onClick="Clear();" id="textbox4>

Javascript :

function Clear()
{    
   document.getElementById("textbox1").value= "";
   document.getElementById("textbox2").value= "";
   document.getElementById("textbox3").value= "";
   document.getElementById("textbox4").value= "";
}

Your question was a little vague to me, but the above will clear all the textboxes when one is clicked. Hopefully this helps you.

like image 200
notknown7777 Avatar answered Sep 29 '22 22:09

notknown7777


One Line solution

  <input type="text" value="" onClick="this.value='';" id="textbox1">

or

 <input type="text" value="" onClick="this.value=='Initial Text'?this.value='':this.value;" id="textbox1">
like image 31
Bellash Avatar answered Sep 29 '22 23:09

Bellash