<?xml version='1.0' encoding='UTF-8'?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:blogger="http://schemas.google.com/blogger/2008" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-4883687672496160895</atom:id><lastBuildDate>Wed, 25 Sep 2024 23:59:26 +0000</lastBuildDate><category>iterator</category><category>javascript</category><category>javascript repeater</category><category>jsrepeater</category><category>paper carts</category><category>repeater</category><category>template</category><title>White Label</title><description></description><link>http://whitelabelapps.blogspot.com/</link><managingEditor>noreply@blogger.com (Unknown)</managingEditor><generator>Blogger</generator><openSearch:totalResults>4</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4883687672496160895.post-6834383883145805638</guid><pubDate>Thu, 07 Aug 2008 12:55:00 +0000</pubDate><atom:updated>2008-08-09T22:16:29.242+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">javascript repeater</category><category domain="http://www.blogger.com/atom/ns#">jsrepeater</category><title>JSRepeater</title><description>The javascript repeater microsite is &lt;a href=&#39;http://jsrepeater.devprog.com/&#39;&gt;here&lt;/a&gt;.
&lt;br /&gt;&lt;br /&gt;

It&#39;s all very well having JSON data coming from the server, the problem lies in displaying this data in a page. I used to write reams of javascript to append nodes to the DOM but I was looking for something a little more declarative so that each time I wanted to put another piece of data on a page I didn&#39;t have to write yet another hardcoded function.
&lt;br /&gt;&lt;br /&gt;
I tried DOJO&#39;s repeater (dojox.iterator) but there were a few things such as nested repeaters which it didn&#39;t do, I had a look around at some of the other libraries available but none felt quite right, so I decided to write my own javascript repeater.
&lt;br /&gt;&lt;br /&gt;
I Googled the term &#39;JSRepeater&#39; and nothing came up so that&#39;s what I&#39;ll call it.
&lt;br /&gt;&lt;br /&gt;
When the page is loaded the repeater will scan the page for any element which has the attribute template=&#39;true&#39;. It will make a copy of that elements contents to serve as a template. 
&lt;br /&gt;&lt;br /&gt;
When you bind data to that template the repeater it will replace any markers with data from the source data and then place the result in the original template element for each item of data to which it was bound. 
&lt;br /&gt;&lt;br /&gt;
A few examples probably makes this clearer, first we need some JSON data to work with.
&lt;br /&gt;&lt;br /&gt;
var Categories = 
[{&quot;Name&quot; : &quot;Memory&quot;,
    &quot;Subcategories&quot; : [{&quot;Name&quot; : &quot;2 GB&quot;},{&quot;Name&quot; : &quot;3GB&quot;},{&quot;Name&quot; : &quot;4GB&quot;}]},&lt;br /&gt;&lt;br /&gt;
{&quot;Name&quot; : &quot;Hard Drives&quot;,
    &quot;Subcategories&quot; : [{&quot;Name&quot; : &quot;250 GB&quot;},{&quot;Name&quot; : &quot;500 GB&quot;},{&quot;Name&quot; : &quot;500+ GB&quot;}]}&lt;br /&gt;&lt;br /&gt;    
{&quot;Name&quot; : &quot;Graphics&quot;,
    &quot;Subcategories&quot; :  [{&quot;Name&quot; : &quot;Integrated&quot;},{&quot;Name&quot; : &quot;Dedicated&quot;}]}]&lt;br /&gt;&lt;br /&gt;


&lt;strong&gt;Basic Binding&lt;/strong&gt;
&lt;br /&gt;&lt;br /&gt;
In order to display all the categories in an unordered list we could use the following template
&lt;br /&gt;&lt;br /&gt;
&lt;div&gt;&lt;!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #800000;&quot;&gt;ul &lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;=&amp;quot;CategoryList&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt; template&lt;/span&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;=&amp;quot;true&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;
  &lt;/span&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #800000;&quot;&gt;li&lt;/span&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;${Name}&lt;/span&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #800000;&quot;&gt;li&lt;/span&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #800000;&quot;&gt;ul&lt;/span&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;&lt;br /&gt;
In the onload event of the page we would insert the following two lines:
&lt;br /&gt;&lt;br /&gt;
&lt;div&gt;&lt;!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--&gt;&lt;span style=&quot;color: #008000;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt; Initialise the jsRepeater&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;var&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; rpt &lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; jsRepeater();
&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt; Bind the data to the template&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;    rpt.bindTemplate(&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&#39;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;CategoryList&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&#39;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;, Categories);&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;&lt;br /&gt;
which would result in:
&lt;br /&gt;&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;Memory&lt;/li&gt;
&lt;li&gt;Hard Drives&lt;/li&gt;
&lt;li&gt;Graphics&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;&lt;br /&gt;
When we bound the template to the data the JSRepeater looped through each category and wrote out the template we created substituting ${Name} for the Name of the category.
&lt;br /&gt;&lt;br /&gt;
&lt;strong&gt;Binding nested data&lt;/strong&gt;
&lt;br /&gt;&lt;br /&gt;
The previous example only displayed categories but categories have subcategories as well and if we want to display the whole hierarchy in one fould swoop we let the repeater know this by using the context tag e.g.
&lt;br /&gt;&lt;br /&gt;
&lt;div&gt;&lt;!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #800000;&quot;&gt;ol &lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;=&#39;CategoryList2&#39; &lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;template&lt;/span&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;=&#39;true&#39;&lt;/span&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #800000;&quot;&gt;li&lt;/span&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;${Name}
    &lt;/span&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #800000;&quot;&gt;ol&lt;/span&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #800000;&quot;&gt;li &lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;context&lt;/span&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;=&#39;Subcategories&#39;&lt;/span&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;${Name}&lt;/span&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #800000;&quot;&gt;li&lt;/span&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #800000;&quot;&gt;ol&lt;/span&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #800000;&quot;&gt;li&lt;/span&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #800000;&quot;&gt;ol&lt;/span&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;&lt;br /&gt;
Once again the repeater parses the template for each category but when it gets to an element with the context tag it evaluates that against the current category and treats that &amp;lt;li&amp;gt; as a separate inner template and parses it for each subcategory in the current category. Inside that template ${Name} no longer refers to the category but the subcategory.
&lt;br /&gt;&lt;br /&gt;
The result is this:
&lt;br /&gt;&lt;br /&gt;
&lt;ol&gt;
 &lt;li&gt;Memory
&lt;ol&gt;
&lt;li&gt;2 GB&lt;/li&gt;
&lt;li&gt;3 GB&lt;/li&gt;
&lt;li&gt;4 GB&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;

 &lt;li&gt;Hard Drives&lt;ol&gt;
&lt;li&gt;250 GB&lt;/li&gt;
&lt;li&gt;500 GB&lt;/li&gt;
&lt;li&gt;500+ GB&lt;/li&gt;&lt;/ol&gt;
&lt;/li&gt;

 &lt;li&gt;Graphics&lt;ol&gt;
&lt;li&gt;Integrated&lt;/li&gt;
&lt;li&gt;Dedicated&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;

&lt;/ol&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;strong&gt;There is more ...&lt;/strong&gt;
&lt;br /&gt;&lt;br /&gt;
The jsRepeater does a lot more than this but a blog is not the place to go into all the details. To that end I have put up a microsite at &lt;a href=&#39;http://jsrepeater.devprog.com/&#39;&gt;jsRepeater&lt;/a&gt;, please check it out and see what other functionality jsRepeater has to offer.</description><link>http://whitelabelapps.blogspot.com/2008/08/jsrepeater.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>2</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4883687672496160895.post-3345265458297585531</guid><pubDate>Sun, 03 Aug 2008 10:02:00 +0000</pubDate><atom:updated>2008-08-03T11:44:55.104+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">paper carts</category><title>Gadget Paper Cart</title><description>&lt;a href=&quot;http://whitelabelfiles.devprog.com/gadgets/site/index.html&quot;&gt;&lt;img style=&quot;float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjp08bNK0rt4mPzdlmULrbovH9Qs3C5L6frCM8SnXFjjGua0XQD9vKqLFms2wSaZE9XZBlB_1CjLIjgxZYPh_anEMimoXI9gG1UXjkVhHWkC70QOmVCEVwVWXhb0mULnJoPGTN4Aov4YSaT/s320/gadget_screen.jpg&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5230237257045582754&quot; /&gt;&lt;/a&gt;
The Gadget Paper Cart is based on a template from &lt;a href=&#39;http://www.freewebsitetemplates.com/forum/showthread.php?t=2936&#39;&gt;Free Website Templates&lt;/a&gt;.
&lt;br /&gt;&lt;br /&gt;
Using the CSS Body Snatching technique that I mentioned in my previous post I have added functionality to this template to give it the feel of a regular shopping cart.
&lt;br /&gt;&lt;br /&gt;
If all you see is a CSS template you have to imagine how it would work in real life. Adding a bit of javascript gives you the chance to test drive the template in action. You can now get a feel for the user friendliness of the design itself.
&lt;br /&gt;&lt;br /&gt;
You can see the template &lt;a href=&#39;http://whitelabelfiles.devprog.com/gadgets/site/index.html&#39;&gt;in action&lt;/a&gt;, and, if you want to have a play with the design yourself, &lt;a href=&#39;http://whitelabelfiles.devprog.com/gadgets/gadgets.zip&#39;&gt;download&lt;/a&gt; the source files.</description><link>http://whitelabelapps.blogspot.com/2008/08/gadget-paper-cart.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjp08bNK0rt4mPzdlmULrbovH9Qs3C5L6frCM8SnXFjjGua0XQD9vKqLFms2wSaZE9XZBlB_1CjLIjgxZYPh_anEMimoXI9gG1UXjkVhHWkC70QOmVCEVwVWXhb0mULnJoPGTN4Aov4YSaT/s72-c/gadget_screen.jpg" height="72" width="72"/><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4883687672496160895.post-3842576567995688356</guid><pubDate>Thu, 17 Jul 2008 12:32:00 +0000</pubDate><atom:updated>2008-07-28T16:25:58.574+01:00</atom:updated><title>CSS Body Snatching</title><description>Yes, CSS is the best way to make sure all your &amp;lt;p&amp;gt; tags use the same font but ... 
&lt;br /&gt;&lt;br /&gt;&lt;em&gt;Have you ever thought of using CSS to control the &lt;strong&gt;flow&lt;/strong&gt; of an application&lt;/em&gt;?
&lt;br /&gt;&lt;br /&gt;
... with Body Class Switching, CSS can dictate not only how an application appears, but also how it functions.
&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;
Let’s use the example of an application with lots of user interaction; a shopping cart.
&lt;br /&gt;&lt;br /&gt;
&lt;table style=&#39;margin:0px;&#39;&gt;
        &lt;tr&gt;
            &lt;td&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjlcgtqM4_QZkOH15BwfAC8VYQBZwI2C4julzR475XB3Vjq_-N4TojkoNx4X1nA32_eCkG70Av5W2A66Mbd7dydhYyvJ6_WwoO3DR9LO00sckkEr9rKTd93UOK4yfKKO0uoMvWBx55HIRni/s1600-h/T1.gif&quot;&gt;&lt;img style=&quot;cursor:pointer; cursor:hand;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjlcgtqM4_QZkOH15BwfAC8VYQBZwI2C4julzR475XB3Vjq_-N4TojkoNx4X1nA32_eCkG70Av5W2A66Mbd7dydhYyvJ6_WwoO3DR9LO00sckkEr9rKTd93UOK4yfKKO0uoMvWBx55HIRni/s320/T1.gif&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5223979821063265394&quot; /&gt;&lt;/a&gt;&lt;/td&gt;
            &lt;td&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgHZZlhPElVsrmUkVIokhzielveQQ-yZP0cy86F7OZzyc8MpcltS_okmbzcLZYrFRsMfZl4lFagR0SOWC0OjdOOlAHEOyoi2XCWxZXSnJro21gQQYAx18RrAV0iK_2UkjW8YinvsCeK9lQC/s1600-h/T2.gif&quot;&gt;&lt;img style=&quot;cursor:pointer; cursor:hand;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgHZZlhPElVsrmUkVIokhzielveQQ-yZP0cy86F7OZzyc8MpcltS_okmbzcLZYrFRsMfZl4lFagR0SOWC0OjdOOlAHEOyoi2XCWxZXSnJro21gQQYAx18RrAV0iK_2UkjW8YinvsCeK9lQC/s320/T2.gif&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5223980000058927858&quot; /&gt;&lt;/a&gt;&lt;/td&gt;
            &lt;td&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhI148aQv4z7pHPD7nGecB7_LFStg10Gfes-Wnf4rgQAMjaomLeYsWLItsRrRr1XWfZjXLYoGl4KFXIKHH3ZO1DQwq6oxP4Su5NVmYNGi6hTYtmPho6kn8oOAy0oWsSf4rzik-9WcYT5bvJ/s1600-h/T3.gif&quot;&gt;&lt;img style=&quot;cursor:pointer; cursor:hand;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhI148aQv4z7pHPD7nGecB7_LFStg10Gfes-Wnf4rgQAMjaomLeYsWLItsRrRr1XWfZjXLYoGl4KFXIKHH3ZO1DQwq6oxP4Su5NVmYNGi6hTYtmPho6kn8oOAy0oWsSf4rzik-9WcYT5bvJ/s320/T3.gif&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5223980173484632338&quot; /&gt;&lt;/a&gt;&lt;/td&gt;
            &lt;td&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgbOtkVDzsKrkl_Mrk3GQPGf-WIz4PNhRJAVdsvGEdIMtz82-s6-qp9uxr3vdIGSyVqkMtmMDY4DcPlyvr3bC0RsXVjk-t1lNiUDr0GlIe6V82frnR5r-83e-NhLqygZhcFSsJz32Q-b3Su/s1600-h/T4.gif&quot;&gt;&lt;img style=&quot;cursor:pointer; cursor:hand;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgbOtkVDzsKrkl_Mrk3GQPGf-WIz4PNhRJAVdsvGEdIMtz82-s6-qp9uxr3vdIGSyVqkMtmMDY4DcPlyvr3bC0RsXVjk-t1lNiUDr0GlIe6V82frnR5r-83e-NhLqygZhcFSsJz32Q-b3Su/s320/T4.gif&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5223980341574338610&quot; /&gt;&lt;/a&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;[1]&lt;/td&gt;
            &lt;td&gt;[2]&lt;/td&gt;
            &lt;td&gt;[3]&lt;/td&gt;
            &lt;td&gt;[4]&lt;/td&gt;
        &lt;/tr&gt;
        &lt;/table&gt; 
&lt;ol&gt;
&lt;li&gt;Category selection on the left, visitor selects category ...&lt;/li&gt;
&lt;li&gt;List of matching products, visitor selects product ...&lt;/li&gt;
&lt;li&gt;Full details displayed, visitor select [Add] ...&lt;/li&gt;
&lt;li&gt;My Cart displayed.&lt;/li&gt;
&lt;/ol&gt;
&lt;br /&gt;
In an AJAX application it would normally be javascript that changes the layout as the visitor moves from [1] to [4].
&lt;br /&gt;
If, instead of making assumptions about layout, javascript simply set the class of the body tag then CSS would be able to take over control from there.
&lt;br /&gt;&lt;br /&gt;  
Let&#39;s try that flow again
&lt;br /&gt;&lt;br /&gt;
&lt;strong&gt;[1] -&amp;gt; [2]&lt;/strong&gt;
Visitor clicks a category and Javascript sets the body class
&lt;div style=&#39;margin-left:2em;&#39;&gt;
        &lt;!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --&gt;
        &lt;span style=&quot;color: #0000FF;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #800000;&quot;&gt;body&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #FF0000;&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;=&#39;categoryselected&#39;&lt;/span&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/div&gt;
CSS can now take over and decide to display the product thumbnails
    &lt;div style=&#39;margin-left:2em;&#39;&gt;
        &lt;!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--&gt;
        &lt;span style=&quot;color: #800000;&quot;&gt;.categoryselected #thumbnailcontainer &lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt; display&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;block&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;;&lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;strong&gt;[2] -&amp;gt; [3]&lt;/strong&gt; 
The visitor clicks on a product and javascript says:
    &lt;div style=&#39;margin-left:2em;&#39;&gt;
        &lt;!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --&gt;
        &lt;span style=&quot;color: #0000FF;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #800000;&quot;&gt;body &lt;/span&gt;
        &lt;span style=&quot;color: #FF0000;&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;=&#39;productselected&#39;&lt;/span&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/div&gt;
CSS responds with:
    &lt;div style=&#39;margin-left:2em;&#39;&gt;
        &lt;!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--&gt;
        &lt;span style=&quot;color: #800000;&quot;&gt;.productselected #productdetailcontainer &lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt; display&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;block&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;;&lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;strong&gt;[3] -&amp;gt; [4]&lt;/strong&gt;
The visitor clicks on ‘Add to Cart’ and javascript says:
    &lt;div style=&#39;margin-left:2em;&#39;&gt;
        &lt;!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --&gt;
        &lt;span style=&quot;color: #0000FF;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #800000;&quot;&gt;body &lt;/span&gt;
        &lt;span style=&quot;color: #FF0000;&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;=&#39;addedtocart&#39;&lt;/span&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/div&gt;
CSS replies:
    &lt;div style=&#39;margin-left:2em;&#39;&gt;
        &lt;!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--&gt;
        &lt;span style=&quot;color: #800000;&quot;&gt;.addedtocart #cartcontainer &lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;
            {&lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt; display&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0000FF;&quot;&gt;block&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;;&lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;
                &lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
What has happened is that CSS has taken control of the visual flow application. &lt;br /&gt;&lt;br /&gt;
&lt;strong&gt;Why do it?&lt;/strong&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;em&gt;Control&lt;/em&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;If the javascript is created being someone other than the designer then the designer is in control of what are essentially design decisions.
&lt;br /&gt;&lt;br /&gt;
&lt;em&gt;Maintainability&lt;/em&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;If the layout of the application changes then you don&#39;t have to plough through javascript trying to find out where to mirror the changes.
&lt;br /&gt;&lt;br /&gt;
&lt;em&gt;Portability&lt;/em&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;The same javascript library and server side code can be used to create two apparently different applications simply because they use a different stylesheet.
&lt;br /&gt;&lt;br /&gt;
&lt;em&gt;User friendly&lt;/em&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;You could give your users the choice of how they want to see the application, some might want everything on the screen at the same time in a control panel kind of scenario while other might be more comfortable with basic uncluttered screens.
&lt;br /&gt;&lt;br /&gt;
&lt;em&gt;Philosophical&lt;/em&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Layout is a design decision and hard coding it into javascript blurs the separation between design and functionality.
&lt;br /&gt;&lt;br /&gt;
&lt;a href=&quot;http://whitelabelfiles.devprog.com/electronixstore/site/index.html&quot;&gt;An Example&lt;/a&gt;
&lt;a href=&quot;http://whitelabelfiles.devprog.com/electronixstore/site/index.html&quot;&gt;&lt;img style=&quot;cursor:pointer; cursor:hand;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjm153EC8_PpMDm5z5Rk6hGZztX4amYDhVtM-HL9i97A1oiOTvWiqfq54qemQ9gCbbfmCgpnMoCp0q8_GBxqjsUg7BCNdg8cnJ9oTXxSIZ-6xI2vu2gALdc_zvfX73ayFJkx3ckDftKclPZ/s320/electronix.jpg&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5228086142999414098&quot; /&gt;&lt;/a&gt;</description><link>http://whitelabelapps.blogspot.com/2008/07/css-body-snatching.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjlcgtqM4_QZkOH15BwfAC8VYQBZwI2C4julzR475XB3Vjq_-N4TojkoNx4X1nA32_eCkG70Av5W2A66Mbd7dydhYyvJ6_WwoO3DR9LO00sckkEr9rKTd93UOK4yfKKO0uoMvWBx55HIRni/s72-c/T1.gif" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4883687672496160895.post-1092696259786340977</guid><pubDate>Tue, 15 Jul 2008 13:39:00 +0000</pubDate><atom:updated>2008-07-15T17:21:21.675+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">iterator</category><category domain="http://www.blogger.com/atom/ns#">javascript</category><category domain="http://www.blogger.com/atom/ns#">repeater</category><category domain="http://www.blogger.com/atom/ns#">template</category><title>Simple javascript repeater</title><description>Assume you want to add content to a page after it has loaded such as JSON data retrieved from the server e.g.:
&lt;small&gt;&lt;pre&gt;
&lt;span style=&quot;color:#0000ff;&quot;&gt;var&lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt; data &lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt; [{Name: &lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt;&#39;&lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt;Google&lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt;&#39;&lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt;, URL: &lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt;&#39;&lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt;http://www.google.com&lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt;&#39;&lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt;},
{Name: &lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt;&#39;&lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt;Yahoo&lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt;&#39;&lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt;, URL: &lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt;&#39;&lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt;http://www.yahoo.com&lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt;&#39;&lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt;},
{Name: &lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt;&#39;&lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt;LiveSearch&lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt;&#39;&lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt;, URL: &lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt;&#39;&lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt;http://search.live.com/&lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt;&#39;&lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt;}];&lt;/span&gt;&lt;/pre&gt;&lt;/small&gt;

This content could possibly be displayed as
&lt;small&gt;
&lt;pre&gt;
&lt;span style=&quot;color:#0000ff;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#800000;&quot;&gt;ul&lt;/span&gt;&lt;span style=&quot;color:#0000ff;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color:#0000ff;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#800000;&quot;&gt;li&lt;/span&gt;&lt;span style=&quot;color:#0000ff;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt;Google [http://www.google.com]&lt;/span&gt;&lt;span style=&quot;color:#0000ff;&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color:#800000;&quot;&gt;li&lt;/span&gt;&lt;span style=&quot;color:#0000ff;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color:#0000ff;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#800000;&quot;&gt;li&lt;/span&gt;&lt;span style=&quot;color:#0000ff;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt;Yahoo [http://www.yahoo.com]&lt;/span&gt;&lt;span style=&quot;color:#0000ff;&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color:#800000;&quot;&gt;li&lt;/span&gt;&lt;span style=&quot;color:#0000ff;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color:#0000ff;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#800000;&quot;&gt;li&lt;/span&gt;&lt;span style=&quot;color:#0000ff;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt;LiveSearch [http://search.live.com/]&lt;/span&gt;&lt;span style=&quot;color:#0000ff;&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color:#800000;&quot;&gt;li&lt;/span&gt;&lt;span style=&quot;color:#0000ff;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color:#0000ff;&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color:#800000;&quot;&gt;ul&lt;/span&gt;&lt;span style=&quot;color:#0000ff;&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;/small&gt;
or perhaps
&lt;small&gt;
&lt;pre&gt;
&lt;span style=&quot;color:#0000ff;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#800000;&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color:#0000ff;&quot;&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#800000;&quot;&gt;a &lt;/span&gt;&lt;span style=&quot;color:#ff0000;&quot;&gt;href&lt;/span&gt;&lt;span style=&quot;color:#0000ff;&quot;&gt;=&#39;http://www.google.com&#39;&lt;/span&gt;&lt;span style=&quot;color:#0000ff;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt;Google&lt;/span&gt;&lt;span style=&quot;color:#0000ff;&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color:#800000;&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#0000ff;&quot;&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color:#800000;&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color:#0000ff;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color:#0000ff;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#800000;&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color:#0000ff;&quot;&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#800000;&quot;&gt;a &lt;/span&gt;&lt;span style=&quot;color:#ff0000;&quot;&gt;href&lt;/span&gt;&lt;span style=&quot;color:#0000ff;&quot;&gt;=&#39;http://www.yahoo.com&#39;&lt;/span&gt;&lt;span style=&quot;color:#0000ff;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt;Yahoo&lt;/span&gt;&lt;span style=&quot;color:#0000ff;&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color:#800000;&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#0000ff;&quot;&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color:#800000;&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color:#0000ff;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color:#0000ff;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#800000;&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color:#0000ff;&quot;&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#800000;&quot;&gt;a &lt;/span&gt;&lt;span style=&quot;color:#ff0000;&quot;&gt;href&lt;/span&gt;&lt;span style=&quot;color:#0000ff;&quot;&gt;=&#39;http://search.live.com/&#39;&lt;/span&gt;&lt;span style=&quot;color:#0000ff;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt;LiveSearch&lt;/span&gt;&lt;span style=&quot;color:#0000ff;&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color:#800000;&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#0000ff;&quot;&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color:#800000;&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color:#0000ff;&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;/small&gt;
and you don&#39;t want to have to deal with that issue in the javascript function.

Firstly, create an HTML template of what the contents would look like when displayed. In the template you will have to indicate the bits that would be substituted by the actual data received. In the tradition of many great javascript libraries we&#39;ll use the ${} notation where ${Name} indicates that you want the &#39;Name&#39; property of the data coming in to be placed in that location.
&lt;small&gt;&lt;pre&gt;&lt;div&gt;&lt;!--  Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/  --&gt;&lt;span style=&quot;color:#0000ff;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#800000;&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color:#0000ff;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt;
    &lt;/span&gt;&lt;span style=&quot;color:#0000ff;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#800000;&quot;&gt;a &lt;/span&gt;&lt;span style=&quot;color:#ff0000;&quot;&gt;href&lt;/span&gt;&lt;span style=&quot;color:#0000ff;&quot;&gt;=&#39;${URL}&#39;&lt;/span&gt;&lt;span style=&quot;color:#0000ff;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt;${Name}&lt;/span&gt;&lt;span style=&quot;color:#0000ff;&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color:#800000;&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#0000ff;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color:#0000ff;&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color:#800000;&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color:#0000ff;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;&lt;/small&gt;

Now that we have a template we need a javascript function that can populate it, here&#39;s one
&lt;small&gt;
&lt;pre&gt;
&lt;div&gt;&lt;!--  Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/  --&gt;&lt;span style=&quot;color:#0000ff;&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt; ParseTemplate(aryData, strTemplate)
{
    &lt;/span&gt;&lt;span style=&quot;color:#0000ff;&quot;&gt;var&lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt; result &lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt;;                 
    &lt;/span&gt;&lt;span style=&quot;color:#0000ff;&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#0000ff;&quot;&gt;var&lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt; i &lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt;; i &lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt; data.length; i&lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt;++&lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt;){
        &lt;/span&gt;&lt;span style=&quot;color:#0000ff;&quot;&gt;var&lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt; obj &lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt; aryData[i];          
        result &lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt; strTemplate.replace(
            &lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt;\$\{([&lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt;}]&lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt;)\}&lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt;g,            
            &lt;/span&gt;&lt;span style=&quot;color:#0000ff;&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt;(match, group1) {  
                &lt;/span&gt;&lt;span style=&quot;color:#0000ff;&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt; obj[group1];     
            } );                        
    }
    &lt;/span&gt;&lt;span style=&quot;color:#0000ff;&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt; result;                      
}&lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;&lt;/small&gt;
Now, whenever new data is loaded you simply need to tell the function what template you want to use and where to put the result.
Here is a full code listing to try out:
&lt;textarea rows=&quot;15&quot; cols=&quot;40&quot;&gt;&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
&amp;lt;script type=&quot;text/javascript&quot;&amp;gt;

var data = [{Name: &#39;Google&#39;, URL: &#39;http://www.google.com&#39;}, 
            {Name: &#39;Yahoo&#39;, URL: &#39;http://www.yahoo.com&#39;}, 
            {Name: &#39;LiveSearch&#39;, URL: &#39;http://search.live.com/&#39;}];
    
    
    function ParseTemplate(aryData, strTemplate)
    {
        var result = &quot;&quot;;                     
        for(var i = 0; i &amp;lt; data.length; i++){
            var obj = aryData[i];              
            result += strTemplate.replace(    
                /\$\{([^}]*)\}/g,                
                function(match, group1) {      
                    return obj[group1];         
                } );                            
        }
        return result;                          
    }
    function ParseTemplate1() {
        document.getElementById(&quot;result&quot;).innerHTML = ParseTemplate(data, document.getElementById(&quot;template1&quot;).innerHTML);
    }
    function ParseTemplate2() {
        document.getElementById(&quot;result&quot;).innerHTML = ParseTemplate(data, document.getElementById(&quot;template2&quot;).innerHTML);
    }
&amp;lt;/script&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
&amp;lt;button onclick=&quot;ParseTemplate1();&quot;&amp;gt;Parse Template 1&amp;lt;/button&amp;gt;
&amp;lt;button onclick=&quot;ParseTemplate2();&quot;&amp;gt;Parse Template 2&amp;lt;/button&amp;gt;
&amp;lt;div id=&#39;template1&#39;&amp;gt;
&amp;lt;p&amp;gt;
    &amp;lt;a href=&#39;${URL}&#39;&amp;gt;${Name}&amp;lt;/a&amp;gt;
&amp;lt;/p&amp;gt;
&amp;lt;/div&amp;gt;
&amp;lt;div id=&#39;template2&#39;&amp;gt;
&amp;lt;p&amp;gt;${Name} = ${URL}&amp;lt;/p&amp;gt;
&amp;lt;/div&amp;gt;
&amp;lt;div style=&quot;border:solid 1px;&quot; id=&#39;result&#39;&amp;gt;Results&amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/textarea&gt;</description><link>http://whitelabelapps.blogspot.com/2008/07/simple-javascript-repeater.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item></channel></rss>