I am creating a form which I simplified below to get straight to the point, the JS code is to control the placeholder; hiding on focus and reappear on blur, obviously this now works for the input with id('Name') only. How do I apply these functions to all inputs elements DRY without repeating the code for each input.
var x = document.getElementById("Name");
x.addEventListener("focusin", myFocusFunction);
x.addEventListener("focusout", myBlurFunction);
function myFocusFunction() {
document.getElementById('Name').placeholder= '';
}
function myBlurFunction() {
document.getElementById('Name').placeholder= 'Name';
}
<div id='card'>
<input id='Name' type='text' placeholder='Name'/>
<input id='Age' type='text' placeholder='Age'/>
<input id='Sex' type='text' placeholder='Sex'/>
<input id='Occupation' type='text' placeholder='Occupation'/>
</div>