when my form having one text input field then in console "hello is printed". but when i give 2 input fields then why console is not printing "hello"?

Viewed 20

//why my console does not print when i give 2 input text field in the form ? whats the reason behind that?

        <input type="text" placeholder="name"> // one input text field in the form
       
    </form>
</body>
<script>
    let form=document.getElementById("form");
    form.addEventListener("submit",(event)=>{
        event.preventDefault();
        console.log("hello");// here hello is printing in console after press enter beacuse we have one text input field in form
    })
</script>
</html>

//with 2 input text field in form

<body>
    <form id="form">

        <input type="text" placeholder="name">
        <input type="text" placeholder="age">   // here 2 input fields were given to form 
       
    </form>
</body>
<script>
    let form=document.getElementById("form");
    form.addEventListener("submit",(event)=>{
        event.preventDefault();
        console.log("hello");// here hello is not printing after press enter why ? is this happening because we have 2 inpu fields inside form ? if it is , the how to solve this issue ?
    })
</script>
</html>
0 Answers
Related