Is there a way to clear the default textbox value onclick on textbox and display onblur of multiple textboxes on form page?
function Clear1(str)
{
document.getElementById(str).value= "";
}
function Clear2(str2)
{
var aa1=document.getElementById(str2);
if (aa1.value==""){
document.getElementById(str2).style.backgroundColor = "#ffcccc";
}else{
document.getElementById(str2).style.backgroundColor = "#ffffff";
}
}
<input type="text" value="test1" onClick="Clear1(this.id);" id="textbox1" onblur="Clear2(this.id);">
<input type="text" value="test2" onClick="Clear1(this.id);" id="textbox2" onblur="Clear2(this.id);">
<input type="text" value="test3" onClick="Clear1(this.id);" id="textbox3" onblur="Clear2(this.id);">
<input type="text" value="test4" onClick="Clear1(this.id);" id="textbox4" onblur="Clear2(this.id);">
https://jsfiddle.net/warunamanjula/qy0hvmyq/1/
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">
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.