Javascript Form How to - Show default value is text input is empty








Question

We would like to know how to show default value is text input is empty.

Answer


<!DOCTYPE html>
<html>
<head>
</head><!--from w  w w . j ava  2  s  . c o m-->
<body>
  <input type="text"
    onfocus="if(this.value=='Enter Email Address'){this.value='';}"
    onblur="if(this.value==''){this.value='Enter Email Address';}"
    value="Enter Email Address">
</body>
</html>

The code above is rendered as follows: