Advertisement
Guest User

Untitled

a guest
Sep 25th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. <meta charset="utf-8" />
  2. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  3. <title>Hands-on Project 4-3</title>
  4. <link rel="stylesheet" href="styles.css" />
  5. <script src="modernizr.custom.05819.js"></script>
  6. </head>
  7.  
  8. <body>
  9. <header>
  10. <h1>
  11. Hands-on Project 4-3
  12. </h1>
  13. </header>
  14.  
  15. <article>
  16. <div id="results">
  17. <p id="resultsExpl"></p>
  18. <ul>
  19. <li id="item1"></li>
  20. <li id="item2"></li>
  21. <li id="item3"></li>
  22. <li id="item4"></li>
  23. <li id="item5"></li>
  24. </ul>
  25. </div>
  26. <form>
  27. <fieldset>
  28. <label for="placeBox" id="placeLabel">
  29. Type the name of a place, then click Submit:
  30. </label>
  31. <input type="text" id="placeBox" />
  32. </fieldset>
  33. <fieldset>
  34. <button type="button" id="button" onclick="processInput()">Submit</button>
  35. </fieldset>
  36. </form>
  37. </article>
  38. <script>
  39. var places = []; // new array to store entered places
  40.  
  41. //define variable for HTML elements
  42. var placeBox = document.getElementById("placeBox");
  43.  
  44. // function to add input to array and then generate list after 5th submission
  45. function processInput() {
  46. places.push(placeBox.value); // add input value to array
  47. placeBox.value = ""; // clear input value
  48. placeBox.focus(); // set cursor back in input element
  49. if (places.length >= 5) {
  50. document.getElementById("resultsExpl").innerHTML = "You entered the following places:";
  51. // populate UL element with LI elements
  52. for (var i = 0; i < 5; i++) {
  53. // get item
  54. var li = document.getElementById('item'+(i+1));
  55. li.innerHTML = places[i]; // put place text in it
  56. }
  57. // Clear array in case user starts again
  58. places = [];
  59. }
  60.  
  61. }
  62. </script>
  63. </body>
  64. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement