poll_options.js 966 B

1234567891011121314151617181920212223242526272829303132
  1. var counter = 1;
  2. function addOption(){
  3. //get the poll form
  4. var form = document.getElementById("options");
  5. //create the new poll option
  6. var option = document.createElement("input");
  7. option.setAttribute("type", "input");
  8. option.setAttribute("name", "choice[" + counter + "]");
  9. option.setAttribute("class", "submit");
  10. option.setAttribute("value", "Option " + counter);
  11. var remove = document.createElement("input");
  12. remove.setAttribute("type", "button");
  13. remove.setAttribute("name", "choice[" + counter + "]");
  14. remove.setAttribute("value", "Remove");
  15. remove.setAttribute("onClick", "removeOption(" + counter + ")");
  16. var div = document.createElement("div");
  17. div.setAttribute("id", counter);
  18. //add the option to the form
  19. div.appendChild(option);
  20. div.appendChild(remove);
  21. form.appendChild(div);
  22. counter++;
  23. }
  24. function removeOption( num ){
  25. var option = document.getElementById(num);
  26. option.parentNode.removeChild(option);
  27. }