Hi. I want to include that the user must write something in both forms to submit. For some reason required is not working. Can you point me where the mistake is?
<form>
<div class="formBox">
<label for="name">Име</label>
<input type="text" id="name" placeholder="Име" required/>
</div>
<div class="formBox">
<label for="surname">Презиме</label>
<input type="text" id="surname" placeholder="Презиме" required/>
</div>
<div class="formBox">
<button id="btn" >Започни тест</button>
</div>
</form>
js file
let infs = [];
const addInf= (ev)=>{
ev.preventDefault(); //to stop the form submitting
let inf = {
id: Date.now(),
name: document.getElementById('name').value,
surname: document.getElementById('surname').value
}
infs.push(inf);
//saving to LS
localStorage.setItem('MyInfList', JSON.stringify(infs) );
document.forms[0].reset(); // to clear the form for the next entries
window.location = "index7.html";
}
document.addEventListener('DOMContentLoaded', ()=>{
document.getElementById('btn').addEventListener('click', addInf);
});