I am trying to write a code within a form input such as when the user clicks on the form element (onfocus), the value of the element disappears, but if a user click on any other input element after that (without filling up the previous input element of the form) than the value of the previous element reappears.
The HTML code is shown below:
<label id="color_text">Forename:</label><br />
<input id="f1" class="form-control" type="text" name="forename" value="Forename" /><br /><br />
The JavaScript i am trying to run is shown below:
<script>
var new_id = document.getElementById("f1");
new_id.onfocus = function(){
if (new_id.value == "Forename"){
new_id.value = "";
}
};
new_id.onblur = function() {
if (new_id.value == ""){
new_id.value = "Forename";
}
};