Html code:
<from id="form-1">
First name: <input type="text" name="fname" value=""><br>
Last name: <input type="text" name="lname" value=""><br><br>
<input type="submit" value="Submit">
</from>
<p>Click "Try it" to display the value of each element in the form.</p>
<button id="btn">Try it</button>
<p id="demo"></p>
JS Code:
document.querySelector(’#btn’).addEventListener(‘click’, ()=>{
let input = document.forms[“form-1”];
let text = “”;
for(let i=0; i<=input.length; i++){
text += input.elements[i].value+"<br>";
}
document.getElementById(‘demo’).innerHTML = text;
})
" I don’t know why its not showing the first and last name "