0

Im using the script from here: http://viralpatel.net/blogs/dynamic-add-textbox-input-button-radio-element-html-javascript/

I was wondering how would i go about removing a textbox after they have clicked "add textbox" i need the option to remove certain textboxes.

Thanks

Exoon
  • 1,513
  • 4
  • 20
  • 35
  • Do you want a custom remove button to remove the previously added text box? – AfromanJ Oct 28 '13 at 11:40
  • I want a text link next to the box which appears to say (Remove) then when they click it, will remove the box next to the link. – Exoon Oct 28 '13 at 11:41
  • possible duplicate of [JavaScript: remove element by id](http://stackoverflow.com/questions/3387427/javascript-remove-element-by-id) – Vicky Gonsalves Oct 28 '13 at 11:41

1 Answers1

0

I'm sorry for an incomplete answer but I usually only work with JQuery not pure JavaScript. I Have made a JsFiddle which adds a remove click. You just need to find out how to remove the above sibling (the added text box).

Here is the code I added.

var foo = document.getElementById("fooBar");
var btn = document.createElement("a");
btn.href = '#';
btn.onclick = function () {
//remove button and click here
};

var t = document.createTextNode("Remove");
btn.appendChild(t);    

//Append the element in page (in span)

foo.appendChild(element);
foo.appendChild(btn)
AfromanJ
  • 3,922
  • 3
  • 17
  • 33