Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. function addBookToLibrary(){
  2. let form = document.getElementById('form');
  3.  
  4. const submitButton = document.getElementById('submit');
  5. submitButton.addEventListener('click', submit)
  6.  
  7. alert('Please enter information about the book into the form.');
  8. form.hidden = false;
  9. }
  10.  
  11. function clearLibraryContainer(){
  12. let libElement = document.getElementById('library');
  13. if(libElement.hasChildNodes()){
  14. libElement.childNodes.forEach(function(childNode){
  15. childNode.remove();
  16. });
  17. }
  18. return;
  19. }
  20.  
  21. function submit() {
  22. let title = document.getElementById('title'),
  23. author = document.getElementById('author'),
  24. numPages = document.getElementById('numPages'),
  25. readOrNot = document.getElementsByName('readAnswer');
  26.  
  27. try {
  28. if(title.value == '' || author.value == '' || numPages == ''){
  29. throw new emptyException('You cannot leave any fields blank.');
  30. }
  31. }
  32. catch(err){
  33. alert(err.message);
  34. return;
  35. }
  36.  
  37. readOrNot.forEach(function(radioButton){
  38. if(radioButton.checked){
  39. readOrNot = radioButton.value;
  40. }
  41. });
  42.  
  43. library.push(new Book(title.value, author.value, numPages.value, readOrNot));
  44.  
  45. title.value = '';
  46. author.value = '';
  47. numPages.value = '';
  48. form.hidden = true;
  49. clearLibraryContainer();
  50. render();
  51. return;
  52. }
  53. return;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement