Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE HTML>
- <html>
- <head>
- <title>Addition</title>
- <script type = "text/javascript">
- colorStr = new Array("red", "black", "blue", "yellow", "green", "grey", "cyan", "orange");
- function colorCheck(color)
- {
- for (i =0; i < colorStr.length; i++)
- {
- if (colorStr[i] == color)
- {
- return true;
- }
- }
- }
- function adder()
- {
- unorderedList = document.getElementById("grab")
- el = document.getElementById("info")
- if (colorCheck(el.value)){
- listElement = document.createElement("li");
- listElement.innerHTML = el.value;
- unorderedList.appendChild(listElement).style.color = el.value;
- }
- else
- alert("not a color");
- }
- function remover()
- {
- ulCheck = document.getElementById("grab").innerHTML;
- if(ulCheck == ""){
- alert ("nothing to remove");
- return;}
- else {
- unorderedList = document.getElementById("grab")
- el = document.getElementById("info")
- unorderedList.removeChild(unorderedList.lastChild);
- }
- }
- </script>
- </head>
- <body>
- <div> Enter one of the following colors: red, black, blue, yellow, green, grey, cyan, orange </div>
- <input type="textbox" value="type here" onclick = "value=''" id = "info" />
- <input type="button" value = "Add" onclick = "adder();" />
- <input type="button" value = "Remove" onclick = "remover();" />
- <ul id = "grab">
- </ul>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement