<?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>EnricoSimonetti.com &#187; W3C</title>
	<atom:link href="http://enricosimonetti.com/tag/w3c/feed/" rel="self" type="application/rss+xml" />
	<link>http://enricosimonetti.com</link>
	<description>Enrico Simonetti's Personal Blog</description>
	<lastBuildDate>Mon, 04 Apr 2011 13:32:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Another battle against IE</title>
		<link>http://enricosimonetti.com/2009/03/21/another-battle-against-ie/</link>
		<comments>http://enricosimonetti.com/2009/03/21/another-battle-against-ie/#comments</comments>
		<pubDate>Sat, 21 Mar 2009 02:49:55 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Teckie]]></category>
		<category><![CDATA[Browsers Compatibility]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[W3C]]></category>

		<guid isPermaLink="false">http://enricosimonetti.com/?p=108</guid>
		<description><![CDATA[As usual, I was playing around with my new project, implementing something similar to Google Suggests for country/city suggestions, after using Google Map Geolocation. Basically the idea was to see a dynamic html table underneath every country/city text field, that suggests the possible values the user is typing. Everything is generated appending child elements through [...]]]></description>
			<content:encoded><![CDATA[<p>As usual, I was playing around with my new project, implementing something similar to <a rel="nofollow" href="http://www.google.com/webhp?complete=1" onclick="return TrackClick('http%3A%2F%2Fwww.google.com%2Fwebhp%3Fcomplete%3D1','Google+Suggests')" target="_blank">Google Suggests</a> for country/city suggestions, after using <a rel="nofollow" href="http://code.google.com/apis/maps/documentation/" onclick="return TrackClick('http%3A%2F%2Fcode.google.com%2Fapis%2Fmaps%2Fdocumentation%2F','Google+Map+Geolocation')" target="_blank">Google Map Geolocation</a>.</p>
<p>Basically the idea was to see a dynamic html table underneath every country/city text field, that suggests the possible values the user is typing.</p>
<p>Everything is generated appending child elements through javascript and removing them when needed.</p>
<p>As usual no problems with Firefox, but I had to battle a lot to understand the problem with Internet Explorer.</p>
<p>Basically the code was correctly appended inside the right element, but wasn&#8217;t visible using IE!</p>
<p>I could for example alert the innerHTML of the newly created table, but still couldn&#8217;t see it on the browser output.</p>
<p>The code I was using was:</p>
<p><code><br />
// creating table<br />
var mytable = document.createElement('table');<br />
mytable.setAttribute('id','this_table_id');<br />
mytable.className = 'my_class';<br />
&nbsp;<br />
// creating row<br />
var tr = document.createElement('tr');<br />
tr.className = 'new_row';<br />
tr.onclick = function() { do_something(); }<br />
&nbsp;<br />
// creating td<br />
var td = document.createElement('td');<br />
td.innerHTML = "My Td Content";<br />
// adding the td inside the row<br />
tr.appendChild(td);<br />
&nbsp;<br />
// adding the row inside the table<br />
mytable.appendChild(tr)<br />
&nbsp;<br />
var body = document.getElementById('my_page_body');<br />
// adding the new table inside the page body<br />
body.appendChild(mytable);<br />
&nbsp;<br />
</code></p>
<p>After few tests and headaches, I had a quick look at MSDN website and noticed that a lot of examples had the &#8220;tbody&#8221; tag in each generated table, why? Let&#8217;s try&#8230;</p>
<p>It worked! Internet Explorer needs the &#8220;tbody&#8221; tag for a table created through javascript to be visible! Crazy stuff.</p>
<p>The working code will look like:</p>
<p><code><br />
// creating table<br />
var mytable = document.createElement('table');<br />
mytable.setAttribute('id','this_table_id');<br />
mytable.className = 'my_class';<br />
&nbsp;<br />
// creating tbody tag<br />
var tbody = document.createElement('tbody');<br />
&nbsp;<br />
// creating row<br />
var tr = document.createElement('tr');<br />
tr.className = 'new_row';<br />
tr.onclick = function() { do_something(); }<br />
&nbsp;<br />
// creating td<br />
var td = document.createElement('td');<br />
td.innerHTML = "My Td Content";<br />
&nbsp;<br />
// adding the td inside the row<br />
tr.appendChild(td);<br />
&nbsp;<br />
// adding the row inside the tbody<br />
tbody.appendChild(tr);<br />
&nbsp;<br />
// adding the tbody inside the table<br />
mytable.appendChild(tbody)<br />
var body = document.getElementById('my_page_body');<br />
&nbsp;<br />
// adding the new table inside the page body<br />
body.appendChild(mytable);<br />
&nbsp;<br />
</code></p>
<p>Yes, I agree that the tag tbody is part of the w3c standard, but on <a rel="nofollow" href="http://www.w3.org/TR/html401/struct/tables.html#h-11.2.1" onclick="return TrackClick('http%3A%2F%2Fwww.w3.org%2FTR%2Fhtml401%2Fstruct%2Ftables.html%23h-11.2.1','HTML+4.01+W3C+standards')" target="_blank">HTML 4.01 W3C standards</a> it is stated the following:</p>
<p><cite><br />
The TBODY start tag is always required except when the table contains only one table body and no table head or foot sections. The TBODY end tag may always be safely omitted.<br />
&nbsp;<br />
</cite></p>
<p>What does it mean? I didn&#8217;t need the tbody, and IE forced me to use it! It CAN&#8217;T be safely omitted <img src='http://enricosimonetti.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p>Another thumb down for IE.</p>
]]></content:encoded>
			<wfw:commentRss>http://enricosimonetti.com/2009/03/21/another-battle-against-ie/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Do you Internet Explorer? I don&#8217;t.</title>
		<link>http://enricosimonetti.com/2009/03/05/do-you-internet-explorer-i-dont/</link>
		<comments>http://enricosimonetti.com/2009/03/05/do-you-internet-explorer-i-dont/#comments</comments>
		<pubDate>Thu, 05 Mar 2009 12:12:20 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Teckie]]></category>
		<category><![CDATA[Browsers Compatibility]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[W3C]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://enricosimonetti.com/?p=87</guid>
		<description><![CDATA[Rants I&#8217;m a web developer and what does a web developer do? He tries to make a website work almost everywhere! Everywhere? According to w3schools browsers stats, the sum of the users of the 2 browsers is about 90% of the whole users, so yeah, everywhere. Here is the problem: we generally love Firefox, we [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Rants</strong></p>
<p>I&#8217;m a web developer and what does a web developer do? He tries to make a website work almost everywhere! <img src='http://enricosimonetti.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>Everywhere? According to <a rel="nofollow" href="http://www.w3schools.com/browsers/browsers_stats.asp" onclick="return TrackClick('http%3A%2F%2Fwww.w3schools.com%2Fbrowsers%2Fbrowsers_stats.asp','w3schools+browsers+stats')" target="_blank">w3schools browsers stats</a>, the sum of the users of the 2 browsers is about 90% of the whole users, so yeah, everywhere.</p>
<p>Here is the problem: we generally love <a rel="nofollow" href="http://www.mozilla.com/firefox/" onclick="return TrackClick('http%3A%2F%2Fwww.mozilla.com%2Ffirefox%2F','Firefox')" target="_blank">Firefox</a>, we really do, because there are so many tools for make your life of debugging a website heaps easier than what it would be with other browsers.</p>
<p>A couple of examples? Of course <a rel="nofollow" href="http://addons.mozilla.org/firefox/addon/1843" onclick="return TrackClick('http%3A%2F%2Faddons.mozilla.org%2Ffirefox%2Faddon%2F1843','Firebug')" target="_blank">Firebug</a> and the <a rel="nofollow" href="http://addons.mozilla.org/firefox/addon/60" onclick="return TrackClick('http%3A%2F%2Faddons.mozilla.org%2Ffirefox%2Faddon%2F60','Web+Developer')" target="_blank">Web Developer</a> addons!<br />
That&#8217;s why we generally start with Firefox to build a website, then we check it on Internet Explorer&#8230; and bam! Nothing works also if you write code/javascript following every single <a rel="nofollow" href="http://www.w3.org" onclick="return TrackClick('http%3A%2F%2Fwww.w3.org','W3C')" target="_blank">W3C</a> standard.</p>
<p>So from that point on, developing will be more like crying blood tears to understand a common way to make things work in both the 2 main browsers user by the &#8220;internet population&#8221;.</p>
<p>But let&#8217;s not get into this, there would be too much to talk about, and it would be only a personal view anyway.</p>
<p>Let&#8217;s talk about the battle I had to win today&#8230;</p>
<p><strong>Objective</strong></p>
<p>I just had to do some pretty basic stuff with checkboxes.</p>
<p>Basically the webpage had a some content (that I couldn&#8217;t modify server side) and I had to add some events through javascript on some checkboxes, to be able to display/hide some parts inside the webpage, on check/uncheck action.</p>
<p>I had to obtain the same feature of a normal &#8220;onclick&#8221; like this:</p>
<p><code>&lt;div id='myid' onclick='alert("you clicked me!")' /&gt;</code></p>
<p>&#8230; dynamically.</p>
<p><strong>Events&#8230; what about them?</strong></p>
<p>How everyone knows, Internet Explorer uses its own weird way of handling events&#8230; and yeah who says that I am right? <a rel="nofollow" href="http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-EventTarget-addEventListener" onclick="return TrackClick('http%3A%2F%2Fwww.w3.org%2FTR%2FDOM-Level-2-Events%2Fevents.html%23Events-EventTarget-addEventListener','W3C+standards')" target="_blank">W3C standards</a> of course! <img src='http://enricosimonetti.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
(and anyway I&#8217;m carrying Firefox&#8217;s flag, so there we go <img src='http://enricosimonetti.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> )</p>
<p>Anyway going back to the point, everyone knows that there are two<br />
 types of event handling:</p>
<p>1) Firefox (W3C compatible):</p>
<p><code><br />
myDomElement.addEventListener('eventType', function()<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;/* some stuff here */<br />
&nbsp;&nbsp;}, bool<br />
);<br />
</code></p>
<p>2) IE:</p>
<p><code><br />
myDomElement.attachEvent('theirEventType', function()<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;/* some stuff here */<br />
&nbsp;&nbsp;}<br />
);<br />
</code></p>
<p>&#8230;and until here all good&#8230;</p>
<p>So a basic &#8220;browser detecting&#8221; would be something like:</p>
<p><code><br />
if(window.addEventListener)<br />
{<br />
&nbsp;&nbsp;/* My W3C Friends */<br />
}<br />
else<br />
{<br />
&nbsp;&nbsp;/* Evil Browsers */<br />
}<br />
</code></p>
<p>Then I&#8217;ve added my dirty little code on it&#8230; to attach events on the 2 browsers&#8230;</p>
<p><code><br />
if(window.addEventListener)<br />
{<br />
&nbsp;&nbsp;    myElement.addEventListener('click', function()<br />
&nbsp;&nbsp;&nbsp;&nbsp;        {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;            checkboxChange(this, my_array_of_fields);<br />
&nbsp;&nbsp;&nbsp;&nbsp;        }, false<br />
&nbsp;&nbsp;    );<br />
}<br />
else<br />
{<br />
&nbsp;&nbsp;    myElement.attachEvent('onclick', function()<br />
&nbsp;&nbsp;&nbsp;&nbsp;        {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;            checkboxChange(this, my_array_of_fields);<br />
&nbsp;&nbsp;&nbsp;&nbsp;        }<br />
&nbsp;&nbsp;    );<br />
}<br />
</code></p>
<p>As said before&#8230; I have a look at the result on Firefox&#8230; and all works fine&#8230; then I move to IE&#8230; and THUNDERSTORMS!<br />
The above code (OF COURSE) doesn&#8217;t work!</p>
<p>Why? WHY???<br />
After digging for a while I&#8217;ve figured out that the name of the object &#8220;this&#8221; passed to the function</p>
<p><code>checkboxChange(...)</code></p>
<p>was not the name of the object I was passing.<br />
I couldn&#8217;t even get the right element through the ID, because of another problem there is with IE!</p>
<p><code>document.getElementById('myId')</code></p>
<p>IE gets confused, if you have the name of an element, equal to the id of another element and that (not my choice) was the case.<br />
So there we go, we have to find another solution!</p>
<p><strong>Solutions? Workarounds?</strong></p>
<p>Of course the easiest way (and also browser indipendent) is&#8230; to use a library that someone &#8220;maybe smarter than you&#8221; wrote already <img src='http://enricosimonetti.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>For example:</p>
<p><a rel="nofollow" href="http://developer.yahoo.com/yui/" onclick="return TrackClick('http%3A%2F%2Fdeveloper.yahoo.com%2Fyui%2F','YAHOO')" target="_blank">YAHOO</a> one</p>
<p><code><br />
YAHOO.util.Event.addListener(myElement, 'click', function()<br />
&nbsp;&nbsp;        {<br />
&nbsp;&nbsp;&nbsp;&nbsp;            checkboxChange(this, my_array_of_fields);<br />
&nbsp;&nbsp;        }<br />
);<br />
</code></p>
<p>or my favorite one <a rel="nofollow" href="http://mootools.net" onclick="return TrackClick('http%3A%2F%2Fmootools.net','MooTools')" target="_blank">MooTools</a></p>
<p><code><br />
myElement.addEvent('click', function()<br />
&nbsp;&nbsp;        {<br />
&nbsp;&nbsp;&nbsp;&nbsp;            checkboxChange(this, my_array_of_fields);<br />
&nbsp;&nbsp;        }<br />
);<br />
</code></p>
<p>Figuring out that there weren&#8217;t other &#8220;onclick&#8221; events in the page for the element I was applying events on, I&#8217;ve decided to don&#8217;t use any external javascript library for this project.<br />
I&#8217;ve used instead an anonymous function associated to the onclick event listener of my element as below:</p>
<p><code><br />
myElement.onclick = function ()<br />
{<br />
&nbsp;&nbsp;checkboxChange(this, my_array_of_fields);<br />
}<br />
</code></p>
<p>This&#8230; just for IE of course <img src='http://enricosimonetti.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>For Firefox instead I&#8217;m still using the addEventListener!</p>
<p>Hopefully I&#8217;ve been helpful to someone with this article <img src='http://enricosimonetti.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>See ya next!</p>
]]></content:encoded>
			<wfw:commentRss>http://enricosimonetti.com/2009/03/05/do-you-internet-explorer-i-dont/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

