The following is a script which empties the Username text field and the Password text field when the it is clicked upon. I want if the user starts filling the password field with username field empty the username field should get filled with its default value and the same goes for the password field. Though the text field gets emptied upon the click it doesn’t get filled with the values if the user proceeds with filling the next field leaving the other field empty for that moment. What is the problem ?
<script type="text/javascript">
function emptyTextField() {
document.getElementById("username").value="";
if( document.getElementById("password").value =="" ) {
document.getElementById("password").value == "password";
}
}
function emptyPasswordField() {
document.getElementById("password").value="";
if( document.getElementById("username").value == "" ) {
document.getElementById("username").value == "Username or Email";
}
}
HTML code :
<ul> <form method="post" action="#">
<li> <input type="text" id="username" value="Username or Email" size="25" name="UserID" onfocus="emptyTextField()" /> </li>
<li> <input type="password" id="password" value="password" size="25" name="UserPassword" onfocus="emptyPasswordField()" />
<center><input type="submit" value="sign-in" style="font-size:20px" /> </center>
</li>
</form>
</ul>
You made one mistake:
to
The = was == .