there's a weird thing happening when I have an input field selected and I click a button to change the placeholder / onblur holder. When I'm looking at the F12 tools in the browser a new HTML source document is created which only contains the previously selected placeholder after clicking on a button to change the placeholder.
ie. if I select input field "First Name" and I my current language selection is English, after clicking a button which changes the onblur placeholder to Italian, the HTML document only contains the English first name set in the onblur function and nothing else (no HTML, no body, nothing...).
Why and how is this happening? How can I prevent this from happening.
You can reproduce the problem with this code.
1.) open the F12 tools
2.) select any input field
3.) click on any of the buttons
let fname = document.getElementById("fname"); let lname = document.getElementById("lname"); let email = document.getElementById("email"); const placeholders = { sl: { fname: "Janez", lname: "Novak", email: "[email protected]" }, en: { fname: "John", lname: "Doe", email: "[email protected]" }, de: { fname: "Kommissar", lname: "Rex", email: "[email protected]" }, it: { fname: "Julius", lname: "Cezar", email: "[email protected]"}, hr: { fname: "Mirko", lname: "Mirkic", email: "[email protected]"}, ru: { fname: "Joseph", lname: "Lenin", email: "[email protected]"} }; const blurholders = { sl: { fname: "Janez", lname: "Novak", email: "[email protected]" }, en: { fname: "John", lname: "Doe", email: "[email protected]" }, de: { fname: "Kommissar", lname: "Rex", email: "[email protected]" }, it: { fname: "Julius", lname: "Cezar", email: "[email protected]"}, hr: { fname: "Mirko", lname: "Mirkic", email: "[email protected]"}, ru: { fname: "Joseph", lname: "Lenin", email: "[email protected]"} }; function setInputs(language) { if (Object.keys(placeholders).includes(language)){ const values = placeholders[language]; fname.setAttribute("placeholder", values.fname); lname.setAttribute("placeholder", values.lname); email.setAttribute("placeholder", values.email); } } function setOnBlurs(language) { if(Object.keys(blurholders).includes(language)){ const valuesB = blurholders[language]; fname.setAttribute("onblur", valuesB.fname); lname.setAttribute("onblur", valuesB.lname); email.setAttribute("onblur", valuesB.email); } } <input type="text" name="fname" id="fname" required maxlength="50" minlength="1" placeholder="Janez" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Janez'" /><br /> <input type="text" name="lname" id="lname" required maxlength="50" minlength="1" placeholder="Novak" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Novak'" /><br /> <input type="email" name="email" id="email" autofocus="autofocus" required placeholder="[email protected]" onfocus="this.placeholder = ''" onblur="this.placeholder = '[email protected]'" /> <br /> <input type="button" value="setInputs SI" onclick="setInputs('sl'); setOnBlurs('sl');"> <input type="button" value="setInputs EN" onclick="setInputs('en'); setOnBlurs('en');"> <input type="button" value="setInputs DE" onclick="setInputs('de'); setOnBlurs('de');"> <input type="button" value="setInputs IT" onclick="setInputs('it'); setOnBlurs('it');"> <input type="button" value="setInputs HR" onclick="setInputs('hr'); setOnBlurs('hr');"> <input type="button" value="setInputs RU" onclick="setInputs('ru'); setOnBlurs('ru');">