Skip to content

Commit fb6f544

Browse files
committed
refactor: remove onClick attribute to submit button and assigned event listener in the script. Also renamed submit function to addBook
1 parent 61339a5 commit fb6f544

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

‎debugging/book-library/index.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ <h1>Library</h1>
6565
type="submit"
6666
value="Submit"
6767
class="btn btn-primary"
68-
onclick="submit()"
68+
id="submit-button"
6969
/>
7070
</div>
7171
</div>

‎debugging/book-library/script.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ const title = document.getElementById("title");
2424
const author = document.getElementById("author");
2525
const pages = document.getElementById("pages");
2626
const check = document.getElementById("check");
27+
const submitButton = document.getElementById("submit-button");
28+
submitButton.addEventListener("click", addBook);
2729

2830
//check the right input from forms and if its ok -> add the new book (object in array)
2931
//via Book function and start render function
30-
function submit() {
32+
function addBook() {
3133
if (
3234
title.value === null ||
3335
title.value === "" ||

0 commit comments

Comments
 (0)