Need help in (Finding HTML Elements Using document.forms)

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 "

Briefly, did you notice that the form element is mispelled from?

1 Like

I’m watching the code from 2 hours and i don’t even notice this !!! thank you so much man …
Big Reason for not noticing : On web browser the form is displaying perfect…

Anyways thanks alot man :slight_smile:

It works now? cool. yeah, those little things are hard to see–sometimes fresh eyes help!

totally work man :100:

1 Like