Gast1
Gast1

Reputation: 199

Javascript: Clear html input when input loses focus

<input name="input15" type="text" size="50" onblur="var input15 = document.getElementById("input15"); input.value == """/>

Anyone know why the input field isn't getting cleared when I click out of the input box?

I'll type the name "Bob" into the input field then when I click on the blank white space outside the field, the field does not get cleared.

Upvotes: 1

Views: 4017

Answers (3)

Praveen
Praveen

Reputation: 56501

Try the below code.

<html>
  <head>
    <script type="text/javascript">
      function clearText(){
       document.getElementById("input15").value = "";
      }
    </script>
  </head>
  <body>
    <input id="input15" type="text" size="50" onblur="clearText()" /> 
  </body>
</html>

Upvotes: 0

Arun P Johny
Arun P Johny

Reputation: 388316

Try

<input name="input15" type="text" size="50" onblur="this.value=''"/>

Demo: Fiddle

Upvotes: 5

Aditya Nagrath
Aditya Nagrath

Reputation: 421

the name of your var is input15, and then after the semi colon you use input.value rather than input15.value? Also you have the == instead of assignment...

Upvotes: 0

Related Questions