<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Stefan Sobek Blog &#187; javascript</title>
	<atom:link href="http://www.sobek.info/blog/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sobek.info/blog</link>
	<description>Writing about IT, Software Engineering, sports and other stuff</description>
	<lastBuildDate>Mon, 24 Jan 2011 12:50:08 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Load data from csv into html-table</title>
		<link>http://www.sobek.info/blog/2010/06/04/load-data-from-csv-into-html-table/</link>
		<comments>http://www.sobek.info/blog/2010/06/04/load-data-from-csv-into-html-table/#comments</comments>
		<pubDate>Fri, 04 Jun 2010 07:23:09 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Scripting]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[csv]]></category>
		<category><![CDATA[csv2table]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://www.sobek.info/blog/?p=278</guid>
		<description><![CDATA[Situation:
Imagine your customer has a bunch of Excel-files which he wanted to display on a website in html-form. 
Problem:
What can you do here? You can write an importer to a database, or let the customer upload the excel file on a webserver and write a parser for the excel files etc. These are all non-trivial [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Situation:</strong><br />
Imagine your customer has a bunch of Excel-files which he wanted to display on a website in html-form. </p>
<p><strong>Problem:</strong><br />
What can you do here? You can write an importer to a database, or let the customer upload the excel file on a webserver and write a parser for the excel files etc. These are all non-trivial solutions for the problem that you want to easily display your information from the csv on a webpage into a table. </p>
<p><strong>Solution: </strong><br />
I found a plugin called jquery csv2table. This is very simple to use. A CSV-file will be read asynchrounosly and a HTML-table will be created of it. So you can simply let your customer load his csv file up and the table will be created automatically. Optional support of sorting, highlighting etc. Link: http://plugins.jquery.com/project/csv2table</p>
<p><strong>Example: </strong></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p278code2'); return false;">View Code</a> JAVASCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p2782"><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="p278code2"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;view1&quot;</span><span style="color: #339933;">&gt;&lt;/</span>div<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
$<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#view1'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">csv2table</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'./data/Book12.csv'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>This code will load the data from Book12.csv into the div &#8220;view1&#8243;. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.sobek.info/blog/2010/06/04/load-data-from-csv-into-html-table/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jquery introduction part 1</title>
		<link>http://www.sobek.info/blog/2010/04/01/jquery-introduction-part-1/</link>
		<comments>http://www.sobek.info/blog/2010/04/01/jquery-introduction-part-1/#comments</comments>
		<pubDate>Thu, 01 Apr 2010 09:00:44 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[HTML]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[jquery introduction]]></category>

		<guid isPermaLink="false">http://www.sobek.info/blog/?p=262</guid>
		<description><![CDATA[Why jquery or why use a js-lib at all?
There are many Javascript libraries on the market, e.g. script.aculo.us, jquery, dojo, Prototype and so on. For most of the tasks there is no special reason why jquery. It ist mostly a matter of actual knowledge of the developers to keep learning time low when there is [...]]]></description>
			<content:encoded><![CDATA[<h3><strong>Why jquery or why use a js-lib at all?</strong></h3>
<p>There are many Javascript libraries on the market, e.g. script.aculo.us, jquery, dojo, Prototype and so on. For most of the tasks there is no special reason why jquery. It ist mostly a matter of actual knowledge of the developers to keep learning time low when there is a basic knowledge available. Some JS-libs have an easier handling e.g. of json than other, in detail using json in jquery is simpler than in prototype.</p>
<p>Why should you use a js-lib at all? There are several reasons:</p>
<h4><strong>Simpler syntax and less code</strong></h4>
<p>Imagine you want to modify every div-element which has class &#8220;payment&#8221; assigned and want to set the background color to &#8220;#cccccc&#8221; to these elements.<br />
You have something like this:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p262code7'); return false;">View Code</a> HTML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p2627"><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="p262code7"><pre class="html" style="font-family:monospace;">&lt;div id=&quot;list&quot;&gt;
  &lt;div class=&quot;payment&quot;&gt;some text&lt;/div&gt;
  &lt;div&gt;some text&lt;/div&gt;
  &lt;div class=&quot;payment&quot;&gt;some text&lt;/div&gt;
  &lt;div class=&quot;payment&quot;&gt;some text&lt;/div&gt;
&lt;/div&gt;</pre></td></tr></table></div>

<p>With normal JS you could do the job like this:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p262code8'); return false;">View Code</a> JAVASCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p2628"><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="p262code8"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> list <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'list'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> list.<span style="color: #660066;">childNodes</span>.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>list.<span style="color: #660066;">childNodes</span>.<span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">className</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">&quot;payment&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    	list.<span style="color: #660066;">childNodes</span>.<span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">style</span>.<span style="color: #660066;">backgroundColor</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'#cccccc'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Ok, six lines of code and moderate readable but what with all browser support? Umpf. And imagine this is a simple example.</p>
<p>With jquery you do:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p262code9'); return false;">View Code</a> JAVASCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p2629"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p262code9"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.payment'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'background-color'</span> <span style="color: #339933;">,</span> <span style="color: #3366CC;">'#cccccc'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>And this runs in all browsers.</p>
<h4><strong>Better readability</strong></h4>
<p>Isn&#8217;t the example above better readable? You use css-selectors for selecting elements in javascript.</p>
<p>E.g. you want to remove the class from the div elements which are childs of the div with id &#8220;list&#8221;.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p262code10'); return false;">View Code</a> JAVASCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p26210"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p262code10"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div#list div.payment'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'payment'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span></pre></td></tr></table></div>

<h4><strong>Better and easier extendability </strong></h4>
<p>You can simply create own plugins.</p>
<h4><strong>Multi-Browser compatibility</strong></h4>
<p>Nearly all functions will run in every browser.</p>
<h3><strong>There are often some cons why you should not use js-libs:</strong></h3>
<h4><strong>Big libray included</strong></h4>
<p>Yes it can be but e.g. with jquery you can use the compressed version for the live version. This will have only round about ~50k. And browser will cache the js file.</p>
<h4><strong>Higher loading times</strong></h4>
<p>Travering can be a costy thing, true. But with newer version it will become faster.</p>
<h3><strong>Conclusion</strong></h3>
<p>So I recommend using jquery because of the better readability, extendability and the separation of concerns.</p>
<h3><strong>Tip of the day: </strong></h3>
<p>Do not put JS-code inside html document when not needed. Use event-handling in outsourced js-file.</p>
<p>More infos about jquery you can find under <a title="jquery" href="http://www.javascriptkata.com/2007/05/29/3-reasons-why-i-use-jquery/" target="_blank">http://www.javascriptkata.com/2007/05/29/3-reasons-why-i-use-jquery/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.sobek.info/blog/2010/04/01/jquery-introduction-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

