<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: How to dynamically add content to a div and store the content to a cookie via JavaScript</title>
	<atom:link href="http://www.randomsnippets.com/2008/04/14/how-to-dynamically-add-content-to-a-div-via-javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.randomsnippets.com/2008/04/14/how-to-dynamically-add-content-to-a-div-via-javascript/</link>
	<description>Random Snippets of Code for Web Developers</description>
	<lastBuildDate>Thu, 19 Jan 2012 11:30:51 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
	<item>
		<title>By: S3nd41</title>
		<link>http://www.randomsnippets.com/2008/04/14/how-to-dynamically-add-content-to-a-div-via-javascript/comment-page-1/#comment-47874</link>
		<dc:creator>S3nd41</dc:creator>
		<pubDate>Wed, 19 Oct 2011 12:44:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/?p=14#comment-47874</guid>
		<description>Hi Allen, actually I got it to work in the meantime, it was a syntax error on the PHP code, it had to be written like this:

addContent(&#039; . &quot;&#039;texto_01&#039;,&#039;&quot; . get(&#039;texto_01&#039;,1,1,1,$page-&gt;ID) . &#039;);

Now it&#039;s working perfectly, thank you very much for your help!</description>
		<content:encoded><![CDATA[<p>Hi Allen, actually I got it to work in the meantime, it was a syntax error on the PHP code, it had to be written like this:</p>
<p>addContent(&#8216; . &#8220;&#8216;texto_01&#8242;,&#8217;&#8221; . get(&#8216;texto_01&#8242;,1,1,1,$page-&gt;ID) . &#8216;);</p>
<p>Now it&#8217;s working perfectly, thank you very much for your help!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Allen Liu</title>
		<link>http://www.randomsnippets.com/2008/04/14/how-to-dynamically-add-content-to-a-div-via-javascript/comment-page-1/#comment-47838</link>
		<dc:creator>Allen Liu</dc:creator>
		<pubDate>Wed, 19 Oct 2011 07:04:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/?p=14#comment-47838</guid>
		<description>Hi S3nd41,

I think I know the issue you are having now.  The addContent() function is a JavaScript function and you are using it as a PHP function which leads to the fatal error that you see.  You will need to add the following JavaScript function to your WordPress:

&lt;pre lang=&quot;javascript&quot;&gt;
function addContent(divName, content) {
     document.getElementById(divName).innerHTML = content;
}
&lt;/pre&gt;

Then, you will need to call this function in your JavaScript code, not your PHP code like you have in pastebin code.

I hope this leads you in the right direction.

Allen</description>
		<content:encoded><![CDATA[<p>Hi S3nd41,</p>
<p>I think I know the issue you are having now.  The addContent() function is a JavaScript function and you are using it as a PHP function which leads to the fatal error that you see.  You will need to add the following JavaScript function to your WordPress:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> addContent<span style="color: #009900;">&#40;</span>divName<span style="color: #339933;">,</span> content<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
     document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span>divName<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">=</span> content<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Then, you will need to call this function in your JavaScript code, not your PHP code like you have in pastebin code.</p>
<p>I hope this leads you in the right direction.</p>
<p>Allen</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: S3nd41</title>
		<link>http://www.randomsnippets.com/2008/04/14/how-to-dynamically-add-content-to-a-div-via-javascript/comment-page-1/#comment-47237</link>
		<dc:creator>S3nd41</dc:creator>
		<pubDate>Sat, 15 Oct 2011 22:54:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/?p=14#comment-47237</guid>
		<description>Sorry but I couldn&#039;t reply to the other thread, don&#039;t know why. I&#039;m not sure I know what you mean. I&#039;ve used your function on the link:
addContent(&#039;texto_01&#039;, get(&quot;texto_01&quot;,1,1,1,$page-&gt;ID) )
The value is fetched using get from a custom field.
The script is placed on my header file and functions.php should be able to find it like I did with the Showhide script, right?</description>
		<content:encoded><![CDATA[<p>Sorry but I couldn&#8217;t reply to the other thread, don&#8217;t know why. I&#8217;m not sure I know what you mean. I&#8217;ve used your function on the link:<br />
addContent(&#8216;texto_01&#8242;, get(&#8220;texto_01&#8243;,1,1,1,$page-&gt;ID) )<br />
The value is fetched using get from a custom field.<br />
The script is placed on my header file and functions.php should be able to find it like I did with the Showhide script, right?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Allen Liu</title>
		<link>http://www.randomsnippets.com/2008/04/14/how-to-dynamically-add-content-to-a-div-via-javascript/comment-page-1/#comment-47074</link>
		<dc:creator>Allen Liu</dc:creator>
		<pubDate>Sat, 15 Oct 2011 05:51:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/?p=14#comment-47074</guid>
		<description>Hi S3nd41,

I do not see the addContent() PHP function defined in your file which is the one causing the issue.

Allen</description>
		<content:encoded><![CDATA[<p>Hi S3nd41,</p>
<p>I do not see the addContent() PHP function defined in your file which is the one causing the issue.</p>
<p>Allen</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: S3nd41</title>
		<link>http://www.randomsnippets.com/2008/04/14/how-to-dynamically-add-content-to-a-div-via-javascript/comment-page-1/#comment-47019</link>
		<dc:creator>S3nd41</dc:creator>
		<pubDate>Sat, 15 Oct 2011 00:31:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/?p=14#comment-47019</guid>
		<description>This is a custom function I&#039;ve edited to create a dynamic menu system. I&#039;ve pasted the contents here http://pastebin.com/4iXJdxCD if you&#039;d be so kind as to take a look. Your script is on lines 64-67.</description>
		<content:encoded><![CDATA[<p>This is a custom function I&#8217;ve edited to create a dynamic menu system. I&#8217;ve pasted the contents here <a href="http://pastebin.com/4iXJdxCD" rel="nofollow">http://pastebin.com/4iXJdxCD</a> if you&#8217;d be so kind as to take a look. Your script is on lines 64-67.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Allen Liu</title>
		<link>http://www.randomsnippets.com/2008/04/14/how-to-dynamically-add-content-to-a-div-via-javascript/comment-page-1/#comment-47003</link>
		<dc:creator>Allen Liu</dc:creator>
		<pubDate>Fri, 14 Oct 2011 22:57:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/?p=14#comment-47003</guid>
		<description>Hi S3nd41,

It looks like the issue you are having is separate from your edit to the header.php file.  I can see that your JavaScript code is there.  This is a PHP issue where you are calling addContent() function but it has not been defined or loaded.  Have you confirmed that your addContent() function is there?  Is this a custom function or a WordPress function?

Allen</description>
		<content:encoded><![CDATA[<p>Hi S3nd41,</p>
<p>It looks like the issue you are having is separate from your edit to the header.php file.  I can see that your JavaScript code is there.  This is a PHP issue where you are calling addContent() function but it has not been defined or loaded.  Have you confirmed that your addContent() function is there?  Is this a custom function or a WordPress function?</p>
<p>Allen</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: S3nd41</title>
		<link>http://www.randomsnippets.com/2008/04/14/how-to-dynamically-add-content-to-a-div-via-javascript/comment-page-1/#comment-47001</link>
		<dc:creator>S3nd41</dc:creator>
		<pubDate>Fri, 14 Oct 2011 22:49:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/?p=14#comment-47001</guid>
		<description>Hi Allen,

Thank you very much for your reply.
I&#039;ve uploaded the site to a test server at http://www.ciclofragmentos.com/teste/

If you can take a look at it I&#039;d appreciate it.

Thanks in advance!</description>
		<content:encoded><![CDATA[<p>Hi Allen,</p>
<p>Thank you very much for your reply.<br />
I&#8217;ve uploaded the site to a test server at <a href="http://www.ciclofragmentos.com/teste/" rel="nofollow">http://www.ciclofragmentos.com/teste/</a></p>
<p>If you can take a look at it I&#8217;d appreciate it.</p>
<p>Thanks in advance!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Allen Liu</title>
		<link>http://www.randomsnippets.com/2008/04/14/how-to-dynamically-add-content-to-a-div-via-javascript/comment-page-1/#comment-46983</link>
		<dc:creator>Allen Liu</dc:creator>
		<pubDate>Fri, 14 Oct 2011 21:23:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/?p=14#comment-46983</guid>
		<description>Hi S3nd41,

Very strange issue indeed.  One would assume that if JavaScript code makes it into the header.php file in WordPress, that it should be available on all pages.  Your issue sounds like it did not make it though.  Did you confirm that the JavaScript code is not in your raw HTML?  Can you give me a link to a sample page that illustrates this problem?

Allen</description>
		<content:encoded><![CDATA[<p>Hi S3nd41,</p>
<p>Very strange issue indeed.  One would assume that if JavaScript code makes it into the header.php file in WordPress, that it should be available on all pages.  Your issue sounds like it did not make it though.  Did you confirm that the JavaScript code is not in your raw HTML?  Can you give me a link to a sample page that illustrates this problem?</p>
<p>Allen</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: S3nd41</title>
		<link>http://www.randomsnippets.com/2008/04/14/how-to-dynamically-add-content-to-a-div-via-javascript/comment-page-1/#comment-46932</link>
		<dc:creator>S3nd41</dc:creator>
		<pubDate>Fri, 14 Oct 2011 16:34:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/?p=14#comment-46932</guid>
		<description>Strange... I&#039;m using a Wordpress blog and I&#039;ve added the javascript code to my header.php and tried to call it from my functions.php and got a &quot;Fatal error: Call to undefined function addContent()&quot;.

Does anyone know what I might be doing wrong?</description>
		<content:encoded><![CDATA[<p>Strange&#8230; I&#8217;m using a WordPress blog and I&#8217;ve added the javascript code to my header.php and tried to call it from my functions.php and got a &#8220;Fatal error: Call to undefined function addContent()&#8221;.</p>
<p>Does anyone know what I might be doing wrong?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Donald</title>
		<link>http://www.randomsnippets.com/2008/04/14/how-to-dynamically-add-content-to-a-div-via-javascript/comment-page-1/#comment-11688</link>
		<dc:creator>Donald</dc:creator>
		<pubDate>Tue, 23 Feb 2010 15:32:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/?p=14#comment-11688</guid>
		<description>Did anyone ever find out how to use the cookie to retrieve the users last hidden/shown divs ?

I&#039;ve seen tutorials for names etc, but nothing yet on how to keep toggled settings.

I&#039;m looking for toggle2 settings to be kept.

Thanks for any pointers!</description>
		<content:encoded><![CDATA[<p>Did anyone ever find out how to use the cookie to retrieve the users last hidden/shown divs ?</p>
<p>I&#8217;ve seen tutorials for names etc, but nothing yet on how to keep toggled settings.</p>
<p>I&#8217;m looking for toggle2 settings to be kept.</p>
<p>Thanks for any pointers!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: [MW2CC] Admin</title>
		<link>http://www.randomsnippets.com/2008/04/14/how-to-dynamically-add-content-to-a-div-via-javascript/comment-page-1/#comment-9631</link>
		<dc:creator>[MW2CC] Admin</dc:creator>
		<pubDate>Wed, 23 Dec 2009 07:58:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/?p=14#comment-9631</guid>
		<description>Fantastic guide!</description>
		<content:encoded><![CDATA[<p>Fantastic guide!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tom Arnfeld</title>
		<link>http://www.randomsnippets.com/2008/04/14/how-to-dynamically-add-content-to-a-div-via-javascript/comment-page-1/#comment-1681</link>
		<dc:creator>Tom Arnfeld</dc:creator>
		<pubDate>Mon, 16 Mar 2009 19:32:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/?p=14#comment-1681</guid>
		<description>Hey,
Is there a way to save the contents of a  (all of the  inside) with cookies and then when the page loads, open the cookie and display the saved data as the &#039;s inside the  tag?

Also, the user updates the cookie with a link?

Please help.. i would greatly appreciate it :)</description>
		<content:encoded><![CDATA[<p>Hey,<br />
Is there a way to save the contents of a  (all of the  inside) with cookies and then when the page loads, open the cookie and display the saved data as the &#8216;s inside the  tag?</p>
<p>Also, the user updates the cookie with a link?</p>
<p>Please help.. i would greatly appreciate it :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bryan Fox</title>
		<link>http://www.randomsnippets.com/2008/04/14/how-to-dynamically-add-content-to-a-div-via-javascript/comment-page-1/#comment-930</link>
		<dc:creator>Bryan Fox</dc:creator>
		<pubDate>Thu, 11 Dec 2008 20:32:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/?p=14#comment-930</guid>
		<description>Nifty!   Worked the first time!

QUESTION, though.


While making specific use of it I stumbled into a problem that I hope someone can help on.  This may not be the best/only way to skin this cat, but we have a PHP/MySQL page that has to  be modified to ADD rows for data entry when needed.  I have abandoned the traditional DOM object methods of adding a single row, since in this case the addition would be a whole block of rows.  I don&#039;t think I&#039;m smart enough to do that...  

Anyway, an idea hit me to make use of our MySQL dB and store the rows in there, and retrieve them using your method.  




function addContent(divName, content) {
     document.getElementById(divName).innerHTML = content;
}





Content to be added:







Your content will be added dynamically below:


Skipping an ultimate requirement that the content of the addition needs to be invisible and inaccessible, I tried the above out.  It works, but the variable ($_value) has form elements in it, including .   The close of the tag, interrupts the value and throws the remaining code to the page, not awaiting insertion by the Submit Button.

Example:  http://www.facey.com/insert_content1.php


The Submit button successfully produces the part that stayed inside, but you see my problem.

IS THERE A WAY to use this javascript addContent function, incorporate the utility of an ADD button, and avoid using the packaging of FORMS? 



Thanks for any help!



p.s.  The PHP component is transparent.  Direct inclusion of the HTML contained in the variable as the value of TEXTAREA produces the same result.</description>
		<content:encoded><![CDATA[<p>Nifty!   Worked the first time!</p>
<p>QUESTION, though.</p>
<p>While making specific use of it I stumbled into a problem that I hope someone can help on.  This may not be the best/only way to skin this cat, but we have a PHP/MySQL page that has to  be modified to ADD rows for data entry when needed.  I have abandoned the traditional DOM object methods of adding a single row, since in this case the addition would be a whole block of rows.  I don&#8217;t think I&#8217;m smart enough to do that&#8230;  </p>
<p>Anyway, an idea hit me to make use of our MySQL dB and store the rows in there, and retrieve them using your method.  </p>
<p>function addContent(divName, content) {<br />
     document.getElementById(divName).innerHTML = content;<br />
}</p>
<p>Content to be added:</p>
<p>Your content will be added dynamically below:</p>
<p>Skipping an ultimate requirement that the content of the addition needs to be invisible and inaccessible, I tried the above out.  It works, but the variable ($_value) has form elements in it, including .   The close of the tag, interrupts the value and throws the remaining code to the page, not awaiting insertion by the Submit Button.</p>
<p>Example:  <a href="http://www.facey.com/insert_content1.php" rel="nofollow">http://www.facey.com/insert_content1.php</a></p>
<p>The Submit button successfully produces the part that stayed inside, but you see my problem.</p>
<p>IS THERE A WAY to use this javascript addContent function, incorporate the utility of an ADD button, and avoid using the packaging of FORMS? </p>
<p>Thanks for any help!</p>
<p>p.s.  The PHP component is transparent.  Direct inclusion of the HTML contained in the variable as the value of TEXTAREA produces the same result.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Suresh Babu</title>
		<link>http://www.randomsnippets.com/2008/04/14/how-to-dynamically-add-content-to-a-div-via-javascript/comment-page-1/#comment-179</link>
		<dc:creator>Suresh Babu</dc:creator>
		<pubDate>Sun, 03 Aug 2008 02:03:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/?p=14#comment-179</guid>
		<description>Thank you Knix. This is what I was looking for.</description>
		<content:encoded><![CDATA[<p>Thank you Knix. This is what I was looking for.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Knix</title>
		<link>http://www.randomsnippets.com/2008/04/14/how-to-dynamically-add-content-to-a-div-via-javascript/comment-page-1/#comment-178</link>
		<dc:creator>Knix</dc:creator>
		<pubDate>Sat, 02 Aug 2008 17:08:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/?p=14#comment-178</guid>
		<description>Hi suresh babu, 

I finally got around to doing this demo.  I hope this information helps.</description>
		<content:encoded><![CDATA[<p>Hi suresh babu, </p>
<p>I finally got around to doing this demo.  I hope this information helps.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Knix</title>
		<link>http://www.randomsnippets.com/2008/04/14/how-to-dynamically-add-content-to-a-div-via-javascript/comment-page-1/#comment-153</link>
		<dc:creator>Knix</dc:creator>
		<pubDate>Mon, 14 Jul 2008 14:35:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/?p=14#comment-153</guid>
		<description>Hi suresh babu,

You sure can save the content.  There are several ways to do this and I will try to think of the simplest way and post an answer by this evening.</description>
		<content:encoded><![CDATA[<p>Hi suresh babu,</p>
<p>You sure can save the content.  There are several ways to do this and I will try to think of the simplest way and post an answer by this evening.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: suresh babu</title>
		<link>http://www.randomsnippets.com/2008/04/14/how-to-dynamically-add-content-to-a-div-via-javascript/comment-page-1/#comment-152</link>
		<dc:creator>suresh babu</dc:creator>
		<pubDate>Mon, 14 Jul 2008 08:08:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/?p=14#comment-152</guid>
		<description>Is there a way to save this content so that next time when a user opens the page, it should be the new content.</description>
		<content:encoded><![CDATA[<p>Is there a way to save this content so that next time when a user opens the page, it should be the new content.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: suresh babu</title>
		<link>http://www.randomsnippets.com/2008/04/14/how-to-dynamically-add-content-to-a-div-via-javascript/comment-page-1/#comment-151</link>
		<dc:creator>suresh babu</dc:creator>
		<pubDate>Mon, 14 Jul 2008 07:54:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.randomsnippets.com/?p=14#comment-151</guid>
		<description>Great Work. I was trying our such a script. Thanks</description>
		<content:encoded><![CDATA[<p>Great Work. I was trying our such a script. Thanks</p>
]]></content:encoded>
	</item>
</channel>
</rss>

