<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: How to dynamically remove/delete elements via JavaScript</title>
	<atom:link href="http://www.randomsnippets.com/2008/03/26/how-to-dynamically-removedelete-elements-via-javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.randomsnippets.com/2008/03/26/how-to-dynamically-removedelete-elements-via-javascript/</link>
	<description>Random Snippets of Code and Ideas for any Web Developer</description>
	<pubDate>Sat, 20 Mar 2010 20:24:47 +0000</pubDate>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>By: Nagarajan</title>
		<link>http://www.randomsnippets.com/2008/03/26/how-to-dynamically-removedelete-elements-via-javascript/#comment-7028</link>
		<dc:creator>Nagarajan</dc:creator>
		<pubDate>Mon, 28 Sep 2009 07:45:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/2008/03/26/how-to-dynamically-removedelete-elements-via-javascript/#comment-7028</guid>
		<description>hello
these are my add and remove functions,the problem is that remove link not works please help:)here’s my code

function setTextInputs(Select) {
 //alert('hai');
     var howmany = Select[Select.selectedIndex].value, add = true;
	 	alert(howmany);
     var n = 1, Form = Select.form, Div, Input;
	 
     while (Div = document.getElementById('Pin' + n))
	
            if (n++ &#62; howmany) {
                add = false;
                Form.removeChild(Div);
   }
     if (add)
         for (n; n &#60;= howmany; ++n) {
              Div = document.createElement('div');
              Div.setAttribute('id', 'Pin' + n);
              Div.className = 'inputbox';
              Div.appendChild(document.createTextNode('Pin' + n + ': '));
              Form.appendChild(Div);

              Input = document.createElement('input');
              Input.setAttribute('type', 'text');
              Input.setAttribute('name', 'Pin' + n);
              Div.appendChild(Input);
			document.getElementById('one').appendChild(Div);
   }

}</description>
		<content:encoded><![CDATA[<p>hello<br />
these are my add and remove functions,the problem is that remove link not works please help:)here’s my code</p>
<p>function setTextInputs(Select) {<br />
 //alert(&#8217;hai&#8217;);<br />
     var howmany = Select[Select.selectedIndex].value, add = true;<br />
	 	alert(howmany);<br />
     var n = 1, Form = Select.form, Div, Input;</p>
<p>     while (Div = document.getElementById(&#8217;Pin&#8217; + n))</p>
<p>            if (n++ &gt; howmany) {<br />
                add = false;<br />
                Form.removeChild(Div);<br />
   }<br />
     if (add)<br />
         for (n; n &lt;= howmany; ++n) {<br />
              Div = document.createElement(&#8217;div&#8217;);<br />
              Div.setAttribute(&#8217;id&#8217;, &#8216;Pin&#8217; + n);<br />
              Div.className = &#8216;inputbox&#8217;;<br />
              Div.appendChild(document.createTextNode(&#8217;Pin&#8217; + n + &#8216;: &#8216;));<br />
              Form.appendChild(Div);</p>
<p>              Input = document.createElement(&#8217;input&#8217;);<br />
              Input.setAttribute(&#8217;type&#8217;, &#8216;text&#8217;);<br />
              Input.setAttribute(&#8217;name&#8217;, &#8216;Pin&#8217; + n);<br />
              Div.appendChild(Input);<br />
			document.getElementById(&#8217;one&#8217;).appendChild(Div);<br />
   }</p>
<p>}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: nasim</title>
		<link>http://www.randomsnippets.com/2008/03/26/how-to-dynamically-removedelete-elements-via-javascript/#comment-6192</link>
		<dc:creator>nasim</dc:creator>
		<pubDate>Sat, 29 Aug 2009 08:01:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/2008/03/26/how-to-dynamically-removedelete-elements-via-javascript/#comment-6192</guid>
		<description>hello 
these are my add and remove functions,the problem is that remove link only works once and after that it's kinda disabled and does nothing at all,please help:)here's my code

var third_counter = 1;
function adduniversity(divName){
var newdiv = document.createElement('div');
newdiv.innerHTML = "university field&lt;a&gt;remove&lt;/a&gt;";
document.getElementById(divName).appendChild(newdiv);
third_counter++;
}


and my remove function is:

function removeElement(parentDiv, childDiv){    
          var child = document.getElementById(childDiv);
          var parent = document.getElementById(parentDiv);
          parent.removeChild(child);
		  third_counter--;
      }</description>
		<content:encoded><![CDATA[<p>hello<br />
these are my add and remove functions,the problem is that remove link only works once and after that it&#8217;s kinda disabled and does nothing at all,please help:)here&#8217;s my code</p>
<p>var third_counter = 1;<br />
function adduniversity(divName){<br />
var newdiv = document.createElement(&#8217;div&#8217;);<br />
newdiv.innerHTML = &#8220;university field<a>remove</a>&#8220;;<br />
document.getElementById(divName).appendChild(newdiv);<br />
third_counter++;<br />
}</p>
<p>and my remove function is:</p>
<p>function removeElement(parentDiv, childDiv){<br />
          var child = document.getElementById(childDiv);<br />
          var parent = document.getElementById(parentDiv);<br />
          parent.removeChild(child);<br />
		  third_counter&#8211;;<br />
      }</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: friar</title>
		<link>http://www.randomsnippets.com/2008/03/26/how-to-dynamically-removedelete-elements-via-javascript/#comment-6165</link>
		<dc:creator>friar</dc:creator>
		<pubDate>Fri, 28 Aug 2009 05:21:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/2008/03/26/how-to-dynamically-removedelete-elements-via-javascript/#comment-6165</guid>
		<description>


body{background-Color:#0f0}
h1{text-Align:center;text-Decoration:blink}
table{border-Color:yellow}


var stack=new Array();
var olTag=document.createElement('ol');
function pushStack()//WARAY SEMICOLON...... push
{
	if(stack.length&#60;=10)
	{
		var item = document.getElementById("output").value;
		stack.reverse().push(item);
		//alert(stack.reverse());
	}
	else
	{
		alert("10 is the Miaximum Entry")
		return item
	}
}

function listshow(thelist)
{
	var listTag=document.createElement('list');
	for (var i = 0; i &#60; stack.length; i++)
	{
		if(stack.length&#60;=10)
		{
			//stack.splice(1,2);
			var liTag=document.createElement('li');		
			txtNode=document.createTextNode(stack[i]);

		}
	}
		olTag.appendChild(liTag);
		liTag.appendChild(txtNode);
		listTag.appendChild(olTag);
		document.childNodes[0].childNodes[1].appendChild(olTag).style.margin = "30 525px";//append in the HTM document
}

function popStack()//pop........
{
	var popVal = stack.pop();
	var li = document.getElementsByTagName('li');
	li[0].parentNode.removeChild(li[0-0]);
	if (popVal == undefined)
	   return "Nothing left!";
	   else
	   return popVal;
}

function trial()
{
	document.getElementById("output").value = "";
}
function back()
{
	document.getElementById("output").value = item;
}
window.onload=function(){
document.getElementById("output").addEventListener('click',trial,false);
document.getElementById("output").addEventListener('blur',back,false);
}



First Come First Serve






</description>
		<content:encoded><![CDATA[<p>body{background-Color:#0f0}<br />
h1{text-Align:center;text-Decoration:blink}<br />
table{border-Color:yellow}</p>
<p>var stack=new Array();<br />
var olTag=document.createElement(&#8217;ol&#8217;);<br />
function pushStack()//WARAY SEMICOLON&#8230;&#8230; push<br />
{<br />
	if(stack.length&lt;=10)<br />
	{<br />
		var item = document.getElementById(&#8221;output&#8221;).value;<br />
		stack.reverse().push(item);<br />
		//alert(stack.reverse());<br />
	}<br />
	else<br />
	{<br />
		alert(&#8221;10 is the Miaximum Entry&#8221;)<br />
		return item<br />
	}<br />
}</p>
<p>function listshow(thelist)<br />
{<br />
	var listTag=document.createElement(&#8217;list&#8217;);<br />
	for (var i = 0; i &lt; stack.length; i++)<br />
	{<br />
		if(stack.length&lt;=10)<br />
		{<br />
			//stack.splice(1,2);<br />
			var liTag=document.createElement(&#8217;li&#8217;);<br />
			txtNode=document.createTextNode(stack[i]);</p>
<p>		}<br />
	}<br />
		olTag.appendChild(liTag);<br />
		liTag.appendChild(txtNode);<br />
		listTag.appendChild(olTag);<br />
		document.childNodes[0].childNodes[1].appendChild(olTag).style.margin = &#8220;30 525px&#8221;;//append in the HTM document<br />
}</p>
<p>function popStack()//pop&#8230;&#8230;..<br />
{<br />
	var popVal = stack.pop();<br />
	var li = document.getElementsByTagName(&#8217;li&#8217;);<br />
	li[0].parentNode.removeChild(li[0-0]);<br />
	if (popVal == undefined)<br />
	   return &#8220;Nothing left!&#8221;;<br />
	   else<br />
	   return popVal;<br />
}</p>
<p>function trial()<br />
{<br />
	document.getElementById(&#8221;output&#8221;).value = &#8220;&#8221;;<br />
}<br />
function back()<br />
{<br />
	document.getElementById(&#8221;output&#8221;).value = item;<br />
}<br />
window.onload=function(){<br />
document.getElementById(&#8221;output&#8221;).addEventListener(&#8217;click&#8217;,trial,false);<br />
document.getElementById(&#8221;output&#8221;).addEventListener(&#8217;blur&#8217;,back,false);<br />
}</p>
<p>First Come First Serve</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Knix</title>
		<link>http://www.randomsnippets.com/2008/03/26/how-to-dynamically-removedelete-elements-via-javascript/#comment-862</link>
		<dc:creator>Knix</dc:creator>
		<pubDate>Wed, 26 Nov 2008 18:36:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/2008/03/26/how-to-dynamically-removedelete-elements-via-javascript/#comment-862</guid>
		<description>Hi MichThom,

Thanks for posting your solution.  I hope that it will help many others who come to this site =)</description>
		<content:encoded><![CDATA[<p>Hi MichThom,</p>
<p>Thanks for posting your solution.  I hope that it will help many others who come to this site =)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: MichThom</title>
		<link>http://www.randomsnippets.com/2008/03/26/how-to-dynamically-removedelete-elements-via-javascript/#comment-861</link>
		<dc:creator>MichThom</dc:creator>
		<pubDate>Wed, 26 Nov 2008 17:23:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/2008/03/26/how-to-dynamically-removedelete-elements-via-javascript/#comment-861</guid>
		<description>Here is a fully working example, with PHP and mySQL incorporated to prepopulate the form.

My PHP/mySQL technique is out of date and isnt the best method, but my point is to show the add/remove.

http://pastebin.com/f47d4daf


Or, for simplified code of JUST the javascript and form, without a complete implementation:

http://pastebin.com/f76c7c0c2</description>
		<content:encoded><![CDATA[<p>Here is a fully working example, with PHP and mySQL incorporated to prepopulate the form.</p>
<p>My PHP/mySQL technique is out of date and isnt the best method, but my point is to show the add/remove.</p>
<p><a href="http://pastebin.com/f47d4daf" rel="nofollow">http://pastebin.com/f47d4daf</a></p>
<p>Or, for simplified code of JUST the javascript and form, without a complete implementation:</p>
<p><a href="http://pastebin.com/f76c7c0c2" rel="nofollow">http://pastebin.com/f76c7c0c2</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: MichThom</title>
		<link>http://www.randomsnippets.com/2008/03/26/how-to-dynamically-removedelete-elements-via-javascript/#comment-860</link>
		<dc:creator>MichThom</dc:creator>
		<pubDate>Wed, 26 Nov 2008 17:20:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/2008/03/26/how-to-dynamically-removedelete-elements-via-javascript/#comment-860</guid>
		<description>I still couldn't get it to work, but thank you Knix for trying to help me.

I eventually went on to another solution altogether, that does work harmoniously with both adding and removing elements. 

http://pastebin.com/f76c7c0c2

Or for a full example, with PHP/mySQL incorporated to prepopulate the form:

http://pastebin.com/f47d4daf

Please note that I didn't do everything in the best way. I query the database using a deprecated method (I think), and see the note at the top of the code for why my method of updating the form isnt the best. But it DOES work, and my point is to show a fully working example of dynamically adding and removing fields, not of proper PHP/mySQL technique.</description>
		<content:encoded><![CDATA[<p>I still couldn&#8217;t get it to work, but thank you Knix for trying to help me.</p>
<p>I eventually went on to another solution altogether, that does work harmoniously with both adding and removing elements. </p>
<p><a href="http://pastebin.com/f76c7c0c2" rel="nofollow">http://pastebin.com/f76c7c0c2</a></p>
<p>Or for a full example, with PHP/mySQL incorporated to prepopulate the form:</p>
<p><a href="http://pastebin.com/f47d4daf" rel="nofollow">http://pastebin.com/f47d4daf</a></p>
<p>Please note that I didn&#8217;t do everything in the best way. I query the database using a deprecated method (I think), and see the note at the top of the code for why my method of updating the form isnt the best. But it DOES work, and my point is to show a fully working example of dynamically adding and removing fields, not of proper PHP/mySQL technique.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rocky</title>
		<link>http://www.randomsnippets.com/2008/03/26/how-to-dynamically-removedelete-elements-via-javascript/#comment-828</link>
		<dc:creator>rocky</dc:creator>
		<pubDate>Thu, 20 Nov 2008 17:32:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/2008/03/26/how-to-dynamically-removedelete-elements-via-javascript/#comment-828</guid>
		<description>Can you provide an example that utilizes both the add and the remove? Messing with your supplied examples, I am unable to get both functioning harmoniously. Meaning, I can add elements, but I can’t remove those newly added elements.

thank you</description>
		<content:encoded><![CDATA[<p>Can you provide an example that utilizes both the add and the remove? Messing with your supplied examples, I am unable to get both functioning harmoniously. Meaning, I can add elements, but I can’t remove those newly added elements.</p>
<p>thank you</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Knix</title>
		<link>http://www.randomsnippets.com/2008/03/26/how-to-dynamically-removedelete-elements-via-javascript/#comment-824</link>
		<dc:creator>Knix</dc:creator>
		<pubDate>Thu, 20 Nov 2008 06:04:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/2008/03/26/how-to-dynamically-removedelete-elements-via-javascript/#comment-824</guid>
		<description>I have made some edits.  It was done manually so please let me know how it works out for you:

http://pastebin.com/m44815314</description>
		<content:encoded><![CDATA[<p>I have made some edits.  It was done manually so please let me know how it works out for you:</p>
<p><a href="http://pastebin.com/m44815314" rel="nofollow">http://pastebin.com/m44815314</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Knix</title>
		<link>http://www.randomsnippets.com/2008/03/26/how-to-dynamically-removedelete-elements-via-javascript/#comment-823</link>
		<dc:creator>Knix</dc:creator>
		<pubDate>Thu, 20 Nov 2008 05:58:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/2008/03/26/how-to-dynamically-removedelete-elements-via-javascript/#comment-823</guid>
		<description>Hi MichThom,

This does not seem to be an issue with quotes since the code you have given me looks.  I would make sure that all the variables are valid by doing a simple alert on them.  Also, you might want to move the "Gcounter++" line to the first line in the function so you do not have to do the "(Gcounter + 1)" in that second line of the function.  

I do not see genreInput anywhere being used in the function so you might want to make sure you have used the correct variable names.  

I hope this helps.</description>
		<content:encoded><![CDATA[<p>Hi MichThom,</p>
<p>This does not seem to be an issue with quotes since the code you have given me looks.  I would make sure that all the variables are valid by doing a simple alert on them.  Also, you might want to move the &#8220;Gcounter++&#8221; line to the first line in the function so you do not have to do the &#8220;(Gcounter + 1)&#8221; in that second line of the function.  </p>
<p>I do not see genreInput anywhere being used in the function so you might want to make sure you have used the correct variable names.  </p>
<p>I hope this helps.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: MichThom</title>
		<link>http://www.randomsnippets.com/2008/03/26/how-to-dynamically-removedelete-elements-via-javascript/#comment-811</link>
		<dc:creator>MichThom</dc:creator>
		<pubDate>Tue, 18 Nov 2008 20:11:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/2008/03/26/how-to-dynamically-removedelete-elements-via-javascript/#comment-811</guid>
		<description>Code didn't transfer right:

http://pastebin.com/m79f0ba63</description>
		<content:encoded><![CDATA[<p>Code didn&#8217;t transfer right:</p>
<p><a href="http://pastebin.com/m79f0ba63" rel="nofollow">http://pastebin.com/m79f0ba63</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: MichThom</title>
		<link>http://www.randomsnippets.com/2008/03/26/how-to-dynamically-removedelete-elements-via-javascript/#comment-810</link>
		<dc:creator>MichThom</dc:creator>
		<pubDate>Tue, 18 Nov 2008 20:09:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/2008/03/26/how-to-dynamically-removedelete-elements-via-javascript/#comment-810</guid>
		<description>Having the same problem Dooza was -- trying to have each dynamically added element able to be dynamically removed.

function addGenre(genreHTML,divName){

          var newdiv = document.createElement('div');
          newdiv.innerHTML = "Genre " + (Gcounter + 1) + " :  " + genreHTML + " ";
          document.getElementById(divName).appendChild(newdiv);
          Gcounter++;

}

genreHTML is a php-generated list of 's. 
genreInput is the parentDiv.

I've tried every combination of single quotes, double quotes, and escaping that I can think of. It returns javascript errors of either invalid arguments or syntax, depending on the quotes used.

Any help?</description>
		<content:encoded><![CDATA[<p>Having the same problem Dooza was &#8212; trying to have each dynamically added element able to be dynamically removed.</p>
<p>function addGenre(genreHTML,divName){</p>
<p>          var newdiv = document.createElement(&#8217;div&#8217;);<br />
          newdiv.innerHTML = &#8220;Genre &#8221; + (Gcounter + 1) + &#8221; :  &#8221; + genreHTML + &#8221; &#8220;;<br />
          document.getElementById(divName).appendChild(newdiv);<br />
          Gcounter++;</p>
<p>}</p>
<p>genreHTML is a php-generated list of &#8217;s.<br />
genreInput is the parentDiv.</p>
<p>I&#8217;ve tried every combination of single quotes, double quotes, and escaping that I can think of. It returns javascript errors of either invalid arguments or syntax, depending on the quotes used.</p>
<p>Any help?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dooza</title>
		<link>http://www.randomsnippets.com/2008/03/26/how-to-dynamically-removedelete-elements-via-javascript/#comment-588</link>
		<dc:creator>Dooza</dc:creator>
		<pubDate>Thu, 23 Oct 2008 11:46:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/2008/03/26/how-to-dynamically-removedelete-elements-via-javascript/#comment-588</guid>
		<description>I am no javascripter, but I know asp/vbscript, so I knew I had to escape them, just wasn't sure how.

I have now got both the add and remove scripts working, and added counter-- to the remove script so that I could add and remove form fields without hitting the limit. I am very happy with myself, your scripts got me to learn something, so thank you!</description>
		<content:encoded><![CDATA[<p>I am no javascripter, but I know asp/vbscript, so I knew I had to escape them, just wasn&#8217;t sure how.</p>
<p>I have now got both the add and remove scripts working, and added counter&#8211; to the remove script so that I could add and remove form fields without hitting the limit. I am very happy with myself, your scripts got me to learn something, so thank you!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Knix</title>
		<link>http://www.randomsnippets.com/2008/03/26/how-to-dynamically-removedelete-elements-via-javascript/#comment-585</link>
		<dc:creator>Knix</dc:creator>
		<pubDate>Thu, 23 Oct 2008 07:42:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/2008/03/26/how-to-dynamically-removedelete-elements-via-javascript/#comment-585</guid>
		<description>Hi Dooza,

I'm glad you were able to resolve this on your own.  Yea, keeping track of quotes within quotes within quotes can be a really tricky thing!</description>
		<content:encoded><![CDATA[<p>Hi Dooza,</p>
<p>I&#8217;m glad you were able to resolve this on your own.  Yea, keeping track of quotes within quotes within quotes can be a really tricky thing!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dooza</title>
		<link>http://www.randomsnippets.com/2008/03/26/how-to-dynamically-removedelete-elements-via-javascript/#comment-580</link>
		<dc:creator>Dooza</dc:creator>
		<pubDate>Wed, 22 Oct 2008 13:30:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/2008/03/26/how-to-dynamically-removedelete-elements-via-javascript/#comment-580</guid>
		<description>The code didn't paste too well, but I did some more digging and got it working by escaping the single quotes like this:

onClick='removeElement(\"dynamicInput\", \"email" + (counter+1) + "\");' /&#62;</description>
		<content:encoded><![CDATA[<p>The code didn&#8217;t paste too well, but I did some more digging and got it working by escaping the single quotes like this:</p>
<p>onClick=&#8217;removeElement(\&#8221;dynamicInput\&#8221;, \&#8221;email&#8221; + (counter+1) + &#8220;\&#8221;);&#8217; /&gt;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dooza</title>
		<link>http://www.randomsnippets.com/2008/03/26/how-to-dynamically-removedelete-elements-via-javascript/#comment-579</link>
		<dc:creator>Dooza</dc:creator>
		<pubDate>Wed, 22 Oct 2008 12:55:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/2008/03/26/how-to-dynamically-removedelete-elements-via-javascript/#comment-579</guid>
		<description>I am trying to have a add and remove button after each form field that is added. When the buttons aren't generated by the javascript it works, but when they are, they don't work.

My problem is that I don't know what to replace single quoutes with. I can see that double quotes get replaced with a single quote, but what about single quotes? Any help would be really appreciated. 

Here is my code:


var counter = 1;
var limit = 10;
function addInput(divName){
     if (counter == limit)  {
          alert("You have reached the limit of adding " + counter + " inputs");
     }
     else {
          var newdiv = document.createElement('div');
		  newdiv.setAttribute('id','email' + (counter + 1));
          newdiv.innerHTML = "Email " + (counter + 1) + " ";
          document.getElementById(divName).appendChild(newdiv);
          counter++;
     }
}
function removeElement(parentDiv, childDiv){
     if (childDiv == parentDiv) {
          alert("The parent div cannot be removed.");
     }
     else if (document.getElementById(childDiv)) {     
          var child = document.getElementById(childDiv);
          var parent = document.getElementById(parentDiv);
          parent.removeChild(child);
     }
     else {
          alert("Child div has already been removed or does not exist.");
          return false;
     }
}
</description>
		<content:encoded><![CDATA[<p>I am trying to have a add and remove button after each form field that is added. When the buttons aren&#8217;t generated by the javascript it works, but when they are, they don&#8217;t work.</p>
<p>My problem is that I don&#8217;t know what to replace single quoutes with. I can see that double quotes get replaced with a single quote, but what about single quotes? Any help would be really appreciated. </p>
<p>Here is my code:</p>
<p>var counter = 1;<br />
var limit = 10;<br />
function addInput(divName){<br />
     if (counter == limit)  {<br />
          alert(&#8221;You have reached the limit of adding &#8221; + counter + &#8221; inputs&#8221;);<br />
     }<br />
     else {<br />
          var newdiv = document.createElement(&#8217;div&#8217;);<br />
		  newdiv.setAttribute(&#8217;id&#8217;,'email&#8217; + (counter + 1));<br />
          newdiv.innerHTML = &#8220;Email &#8221; + (counter + 1) + &#8221; &#8220;;<br />
          document.getElementById(divName).appendChild(newdiv);<br />
          counter++;<br />
     }<br />
}<br />
function removeElement(parentDiv, childDiv){<br />
     if (childDiv == parentDiv) {<br />
          alert(&#8221;The parent div cannot be removed.&#8221;);<br />
     }<br />
     else if (document.getElementById(childDiv)) {<br />
          var child = document.getElementById(childDiv);<br />
          var parent = document.getElementById(parentDiv);<br />
          parent.removeChild(child);<br />
     }<br />
     else {<br />
          alert(&#8221;Child div has already been removed or does not exist.&#8221;);<br />
          return false;<br />
     }<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Munish Pathak</title>
		<link>http://www.randomsnippets.com/2008/03/26/how-to-dynamically-removedelete-elements-via-javascript/#comment-416</link>
		<dc:creator>Munish Pathak</dc:creator>
		<pubDate>Thu, 25 Sep 2008 09:59:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/2008/03/26/how-to-dynamically-removedelete-elements-via-javascript/#comment-416</guid>
		<description>It was really good, when I tried it.</description>
		<content:encoded><![CDATA[<p>It was really good, when I tried it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Knix</title>
		<link>http://www.randomsnippets.com/2008/03/26/how-to-dynamically-removedelete-elements-via-javascript/#comment-203</link>
		<dc:creator>Knix</dc:creator>
		<pubDate>Wed, 13 Aug 2008 15:24:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/2008/03/26/how-to-dynamically-removedelete-elements-via-javascript/#comment-203</guid>
		<description>Hi Charles,

I noticed a mistake in my edit and edited the link.  Please refer to the new link.

Thanks.</description>
		<content:encoded><![CDATA[<p>Hi Charles,</p>
<p>I noticed a mistake in my edit and edited the link.  Please refer to the new link.</p>
<p>Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Knix</title>
		<link>http://www.randomsnippets.com/2008/03/26/how-to-dynamically-removedelete-elements-via-javascript/#comment-202</link>
		<dc:creator>Knix</dc:creator>
		<pubDate>Wed, 13 Aug 2008 06:09:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/2008/03/26/how-to-dynamically-removedelete-elements-via-javascript/#comment-202</guid>
		<description>Hi Charles,

I think the problem is that you did not indicate an ID for the created child element.  Once you place the ID in there, which is created dynamically using the counter variable, you can also use that same ID for the input button that is used for removing it.

http://pastebin.com/m60464aaa

I have not tested it but I hope the basic idea is there.</description>
		<content:encoded><![CDATA[<p>Hi Charles,</p>
<p>I think the problem is that you did not indicate an ID for the created child element.  Once you place the ID in there, which is created dynamically using the counter variable, you can also use that same ID for the input button that is used for removing it.</p>
<p><a href="http://pastebin.com/m60464aaa" rel="nofollow">http://pastebin.com/m60464aaa</a></p>
<p>I have not tested it but I hope the basic idea is there.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Charles</title>
		<link>http://www.randomsnippets.com/2008/03/26/how-to-dynamically-removedelete-elements-via-javascript/#comment-201</link>
		<dc:creator>Charles</dc:creator>
		<pubDate>Tue, 12 Aug 2008 01:19:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/2008/03/26/how-to-dynamically-removedelete-elements-via-javascript/#comment-201</guid>
		<description>What if the Child is programmatically created? What is it's div ID then? This is the part i'm having the most trouble with. I'm dynamically creating an Input inside a div. Along with this, I'm creating a button to remove the entire div..except, I don't know what to ID to pass into the removeElement function...

I've pasted it in pastebin: http://pastebin.com/m1cf0ba22

It's the first highlighted line. You responded in your other article about dynamic creation that the ID was already available but I'm just not making the logical gap.

Any thoughts would be greatly appreciated.</description>
		<content:encoded><![CDATA[<p>What if the Child is programmatically created? What is it&#8217;s div ID then? This is the part i&#8217;m having the most trouble with. I&#8217;m dynamically creating an Input inside a div. Along with this, I&#8217;m creating a button to remove the entire div..except, I don&#8217;t know what to ID to pass into the removeElement function&#8230;</p>
<p>I&#8217;ve pasted it in pastebin: <a href="http://pastebin.com/m1cf0ba22" rel="nofollow">http://pastebin.com/m1cf0ba22</a></p>
<p>It&#8217;s the first highlighted line. You responded in your other article about dynamic creation that the ID was already available but I&#8217;m just not making the logical gap.</p>
<p>Any thoughts would be greatly appreciated.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: shamim</title>
		<link>http://www.randomsnippets.com/2008/03/26/how-to-dynamically-removedelete-elements-via-javascript/#comment-135</link>
		<dc:creator>shamim</dc:creator>
		<pubDate>Fri, 04 Jul 2008 00:03:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/2008/03/26/how-to-dynamically-removedelete-elements-via-javascript/#comment-135</guid>
		<description>Thank you very very much</description>
		<content:encoded><![CDATA[<p>Thank you very very much</p>
]]></content:encoded>
	</item>
</channel>
</rss>
