I have an input form element. It has a default value MYVALUE. I would like to change this value when in focus. If there is any other value in there, I'd want to leave it unchanged.
Here is my code:
<input
type="text"
name="myInput"
id="myInput"
value="MYVALUE"
style="
width:100%;
font-size:1.2em;
color:blue;
"
onclick="
if (document.getElementById('myInput').value ===.'MYVALUE';) {
document.getElementById('myInput').value ='';
document.getElementById('myInput').style.color ='black';
}
"
>
When the element gets focus, it would do nothing. When I click out of the element, the function executes.
Without the "if", it the function executes on getting the focus, as it should. Any ideas why and how to solve the problem (I need that "if")? Thanks!!
Aucun commentaire:
Enregistrer un commentaire