0
<form id="book-form">
        <div class="form-group">
       
        <input type="submit" value="Add Book" class="btn btn-primary btn-block">
      </form>
document.querySelector('#book-form').addEventListener('submit', (e) => {
  // Prevent actual submit
  e.preventDefault();

  // Get form values
 


  }
});


Every time I open the console, the Uncaught TypeError: document.querySelector(...) is null is shown up and the whole code didn't run properly.

farzadro
  • 13
  • 3

1 Answers1

0

You have multiple syntax errors in your code:

  1. Close your div container.

  2. Remove the second } of addEventListener.

document.querySelector('#book-form').addEventListener('submit', (e) => {

    // Prevent actual submit
    e.preventDefault();

    // Get form values
    console.log("Worked");

});
<form id="book-form">
    <div class="form-group"></div>
    <input type="submit" value="Add Book" class="btn btn-primary btn-block">
</form>
Suboptimierer
  • 554
  • 4
  • 11
  • I had a mistake here and it's that I delete some part of code , Thank you all . I clear that the deleted mistakely and {} contains other function which deleted by me. – farzadro Jan 15 '23 at 08:51