<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-14059684</id><updated>2012-02-16T20:50:17.883-08:00</updated><title type='text'>Mobile Web Blues</title><subtitle type='html'>Challenges in building web applications on mobile webkit browsers.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://jjalan.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/14059684/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://jjalan.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Jaikishan Jalan</name><uri>http://www.blogger.com/profile/04104646893980850789</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://3.bp.blogspot.com/_bzJH8WMGhDA/TSlpIO8rRhI/AAAAAAAAC1Q/SmCsqbro818/S220/114.JPG'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>8</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-14059684.post-4443219898711223498</id><published>2011-02-03T00:05:00.000-08:00</published><updated>2011-02-04T20:05:04.933-08:00</updated><title type='text'>For .... with innerhtml</title><content type='html'>I want to talk about a very simple fact about DOM manipulation using javascript. This is not specific to mobile but is applicable to all the browser in general.&lt;br /&gt;&lt;br /&gt;On a higher level, I want to append three child elements (div) to a div container. I also want to hold a reference in javascript as I want to add/manipulate their content. My javascript was as follows:&lt;br /&gt;&lt;pre class="brush: js"&gt;var domContainer = new Array();&lt;br /&gt;var n = 3;&lt;br /&gt;var p = document.getElementById("parent");&lt;br /&gt;for(var i=0;i&amp;lt;n;i++)&lt;br /&gt;{&lt;br /&gt; var cntId = "cnt"+i; &lt;br /&gt; p.innerHTML += "&amp;lt;div id='"+cntId+"'&amp;gt;&amp;lt;/div&amp;gt;";&lt;br /&gt; domContainer[i] = document.getElementById(cntId);&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;Essentially, I first got hold of the parent container and then changed the inner html of the container to add a child. As soon as I append the child, I get the hold of the child element and store it in the array. To manipulate the content of a child element with index &lt;span style="font-weight:bold;"&gt;i&lt;/span&gt;, I did&lt;br /&gt;&lt;pre class="brush: js"&gt;domContainer[i].innerHTML = "dummy content";&lt;/pre&gt;&lt;br /&gt;To my surprise, for all child container with index &amp;lt; n-1 (in this case for i=0 and 1), browser never displayed the dummy content. It also never fired any javascript error. Interesting, isn't it ? What is happening is here when we are changing the innerHTML of the parent container, it is destroying all the existing child elements of the container and recreating them again along with appending the new child element. From browser perspective, this is what is happening:&lt;br /&gt;&lt;br /&gt;for i=0, it is creating a child element to parent container with id as cnt0;&lt;br /&gt;for i=1, it is destroying the existing child element with id cnt0 and then creating two child elements with id cnt0 and cnt1.&lt;br /&gt;for i=2, it is destroying the existing child elements with id cnt0 and cnt1 and then creating three child elements with id cnt0, cnt1 and cnt2.&lt;br /&gt;&lt;br /&gt;Note that the browser just destory those elements from UX but do not remove it from browser memory as javascript is still holding a reference to those dom objects (in domContainer array). Therefore, by the end of the loop all the values in array for index 0 to n-2 refers to a DOM element which is still in browser memory but are no longer displayed to the user. Since child elements are not re-created after the end of the loop, therefore the element at index n-1 is the same as the one that is currently being displayed. This explains the behavior I was observing. So how did I fixed this ?&lt;br /&gt;&lt;pre class="brush: js"&gt;for(var i=0;i&amp;lt;n;i++)&lt;br /&gt;{&lt;br /&gt; var cntId = "cnt"+i;&lt;br /&gt; var cnt = document.createElement("div");&lt;br /&gt; cnt.setAttribute("id", cntId);&lt;br /&gt; p.appendChild(cnt);&lt;br /&gt; &lt;br /&gt; domContainer[i] = document.getElementById(cntId);&lt;br /&gt;}&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/14059684-4443219898711223498?l=jjalan.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jjalan.blogspot.com/feeds/4443219898711223498/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=14059684&amp;postID=4443219898711223498' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/14059684/posts/default/4443219898711223498'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/14059684/posts/default/4443219898711223498'/><link rel='alternate' type='text/html' href='http://jjalan.blogspot.com/2011/02/for-with-innerhtml.html' title='For .... with innerhtml'/><author><name>Jaikishan Jalan</name><uri>http://www.blogger.com/profile/04104646893980850789</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://3.bp.blogspot.com/_bzJH8WMGhDA/TSlpIO8rRhI/AAAAAAAAC1Q/SmCsqbro818/S220/114.JPG'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-14059684.post-7852120103864528791</id><published>2011-01-31T20:07:00.000-08:00</published><updated>2011-01-31T20:10:00.530-08:00</updated><title type='text'>Why real time feed does not make sense for a news service</title><content type='html'>I am a news savy or I try to be one. I would like to know about the topic as soon as possible. Recently, people started talking about real time feed. And when they say that, they essentially means Twitter feed. They are real time feed because people are tweeting about it somewhere out in real world. In contrast, a search result on web is not considered real time as those are indexed by a web spider at some point of time. That means, ideally real time feed is the best place for me to check about the latest topic. Ok, that make sense. I go to twitter and look at the trending topics. But that just tells me about the topic but not what about it. Sure, I can then look through what people are talking about it. But most of the time, a tweet in itself does not make sense. Sometime people emote about the item. Sometime people talk in twitter code language that I can't understand. After spending some more time, I might be able to understand what the heck is going on. That's OK way to know about something. Let's see the alternative. I take a trending topic and I do a Google/Bing news search. I tried this for some of the trending topic. For most part, I got some very recently published article about it. In this manner, I get all the information at one place and I do not need to compose a story from multiple tweets. &lt;br /&gt;&lt;br /&gt;This brings me back to where I started this article. Where should I go to get the recent news? Why would I ever want to start with real feeds at first place ? A news aggregator/indexer service such as google/bing anyways surface those articles quickly. So why would I ever bother about real time feed ?&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/14059684-7852120103864528791?l=jjalan.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jjalan.blogspot.com/feeds/7852120103864528791/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=14059684&amp;postID=7852120103864528791' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/14059684/posts/default/7852120103864528791'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/14059684/posts/default/7852120103864528791'/><link rel='alternate' type='text/html' href='http://jjalan.blogspot.com/2011/01/why-real-time-feed-does-not-make-sense.html' title='Why real time feed does not make sense for a news service'/><author><name>Jaikishan Jalan</name><uri>http://www.blogger.com/profile/04104646893980850789</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://3.bp.blogspot.com/_bzJH8WMGhDA/TSlpIO8rRhI/AAAAAAAAC1Q/SmCsqbro818/S220/114.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-14059684.post-2502244374289080222</id><published>2011-01-29T13:03:00.000-08:00</published><updated>2011-02-04T19:01:43.464-08:00</updated><title type='text'>Cross domain requests -  how it is not scalable for Mobile Web</title><content type='html'>Many times, you might want to download data from a service hosted on a different or a sub domain. The usual approach is you add a script tag in your DOM with src tag set to the request url. The request url in turn returns javascript that calls a javascript function on your client passing the data as an argument to that function. &lt;br /&gt;&lt;br /&gt;However, this technique is not scalable for all mobile web browsers. I know for sure that this technique fails on HTC Incredible. I will tell you why in a moment. But to verify my claim, I went ahead and looked at Google mobile site. Google Mobile usually hosts its autosuggest service on a different domain (for many reasons - less load on their main production server, increasing maximum number of parallel connections etc.). Look at the server to which the browser makes request for an iPhone and HTC Incredible UA:&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align:center"&gt;&lt;br /&gt;&lt;img src="http://3.bp.blogspot.com/_bzJH8WMGhDA/TUSJLLSoTwI/AAAAAAAAC2Q/hmrsgVJSJaA/s1600/cross-domain-request.png" /&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;As you can see, Google clearly differentiates between these two phones in the way it make request for autosuggest, for iphone case - it uses cross domain request and for HTC incredible, it uses ajax to download the suggestions. What essentially happens in case of HTC incredible is browser gets in old state. If you keep making requests using the same script tag or creating new script tags or each request, the browser does not evaluate the script response from the server immediately. But if you give some sort of poke to browser (by either touching the screen or by invoking alert etc), it will invoke all the pending functions call immediately. &lt;br /&gt;&lt;br /&gt;I wonder on how many other phones this behavior happens. I hope not a lot.&lt;br /&gt;&lt;br /&gt;If you wonder how I produced these waterfall chats, by ofcourse faking the UA from my firefox browser. But may be in future, I can use &lt;a href="http://stevesouders.com/mobileperf/mobileperfbkm.php"&gt;steve souders bookmarklet&lt;/a&gt; to produce waterfall directly on mobile devices.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/14059684-2502244374289080222?l=jjalan.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jjalan.blogspot.com/feeds/2502244374289080222/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=14059684&amp;postID=2502244374289080222' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/14059684/posts/default/2502244374289080222'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/14059684/posts/default/2502244374289080222'/><link rel='alternate' type='text/html' href='http://jjalan.blogspot.com/2011/01/cross-domain-requests-how-it-is-not.html' title='Cross domain requests -  how it is not scalable for Mobile Web'/><author><name>Jaikishan Jalan</name><uri>http://www.blogger.com/profile/04104646893980850789</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://3.bp.blogspot.com/_bzJH8WMGhDA/TSlpIO8rRhI/AAAAAAAAC1Q/SmCsqbro818/S220/114.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_bzJH8WMGhDA/TUSJLLSoTwI/AAAAAAAAC2Q/hmrsgVJSJaA/s72-c/cross-domain-request.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-14059684.post-8696757213435117273</id><published>2011-01-18T23:01:00.000-08:00</published><updated>2011-01-19T00:21:47.253-08:00</updated><title type='text'>Mobile browser market share in US</title><content type='html'>This graph indicates mobile browser share of total mobile internet traffic in US market in past 12 months. Datasource: &lt;a href="http://gs.statcounter.com/"&gt;StatCounter&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_bzJH8WMGhDA/TTaZI_zlw6I/AAAAAAAAC2I/_1BM9AoNm_o/s1600/mobile-browser-monthly.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://1.bp.blogspot.com/_bzJH8WMGhDA/TTaZI_zlw6I/AAAAAAAAC2I/_1BM9AoNm_o/s1600/mobile-browser-monthly.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5563802769508647842" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Trend is clear. More and more mobile traffic is coming from non-iOS devices. On an average over the year, this is how the share looks like&lt;br /&gt;&lt;br /&gt;Blackberry: 29.57%&lt;br /&gt;iPhone: 26.83%&lt;br /&gt;Android: 18.02%&lt;br /&gt;iPod: 13.88%&lt;br /&gt;&lt;br /&gt;Note that the above will not total to 100% as I omitted share for other browsers such as Opera etc as these 4 constituted the top 90% traffic source. Note that all the 4 devices have a webkit browser with HTML 5 capabilities (&lt;a href="http://devblog.blackberry.com/2010/08/developing-new-blackberry-browser/"&gt;Blackberry announced it last year&lt;/a&gt;). This is good news as HTML 5 features would help to a create a user experience which would feel like native app.&lt;br /&gt;&lt;br /&gt;Write once and run everywhere ;)&lt;br /&gt;&lt;br /&gt;EDIT: I just found out that Google recently released &lt;a href="http://developer.android.com/resources/dashboard/platform-versions.html"&gt;the relative number of active devices running a given version of the Android platform&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/14059684-8696757213435117273?l=jjalan.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jjalan.blogspot.com/feeds/8696757213435117273/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=14059684&amp;postID=8696757213435117273' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/14059684/posts/default/8696757213435117273'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/14059684/posts/default/8696757213435117273'/><link rel='alternate' type='text/html' href='http://jjalan.blogspot.com/2011/01/mobile-browser-market-share-in-us.html' title='Mobile browser market share in US'/><author><name>Jaikishan Jalan</name><uri>http://www.blogger.com/profile/04104646893980850789</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://3.bp.blogspot.com/_bzJH8WMGhDA/TSlpIO8rRhI/AAAAAAAAC1Q/SmCsqbro818/S220/114.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_bzJH8WMGhDA/TTaZI_zlw6I/AAAAAAAAC2I/_1BM9AoNm_o/s72-c/mobile-browser-monthly.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-14059684.post-6634866329014101196</id><published>2011-01-14T23:44:00.001-08:00</published><updated>2011-01-14T23:53:55.496-08:00</updated><title type='text'>Mobilism - 12th &amp; 13th of May, 2011: Amsterdam</title><content type='html'>I recently came to know about &lt;a href="http://mobilism.nl/2011"&gt;Mobilism&lt;/a&gt;, the first conference that exclusively focus on web design and development on mobile devices. I am happy to see that mobile web development is getting more and more traction. Few days back, Steve souders, the famous author of &lt;a href="http://stevesouders.com/hpws/rules.php"&gt;High Performance Website&lt;/a&gt; and &lt;a href="http://www.stevesouders.com/blog/2009/04/23/even-faster-web-sites/"&gt;Even faster web sites&lt;/a&gt;, also &lt;a href="http://www.stevesouders.com/blog/2011/01/10/announcing-my-focus-on-mobile/"&gt;announced&lt;/a&gt; that his research wings will now focus on finding bottlenecks and building tools for mobile websites.&lt;br /&gt;&lt;br /&gt;With so many different mobile platforms becoming popular,I believe that the only way to deliver a kick ass experience without creating a big engineering effort is build the experience in html(5) and deliver it through web. &lt;br /&gt;&lt;br /&gt;Go Mobile !&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/14059684-6634866329014101196?l=jjalan.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jjalan.blogspot.com/feeds/6634866329014101196/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=14059684&amp;postID=6634866329014101196' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/14059684/posts/default/6634866329014101196'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/14059684/posts/default/6634866329014101196'/><link rel='alternate' type='text/html' href='http://jjalan.blogspot.com/2011/01/mobilism.html' title='Mobilism - 12th &amp; 13th of May, 2011: Amsterdam'/><author><name>Jaikishan Jalan</name><uri>http://www.blogger.com/profile/04104646893980850789</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://3.bp.blogspot.com/_bzJH8WMGhDA/TSlpIO8rRhI/AAAAAAAAC1Q/SmCsqbro818/S220/114.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-14059684.post-7209207972297121649</id><published>2011-01-09T21:56:00.001-08:00</published><updated>2011-02-04T20:08:05.533-08:00</updated><title type='text'>Enter keyboard event with animation on Samsung sch-i400</title><content type='html'>In this post, I am going to talk about a very surprising animation bug on Samsung SCH-i400 running on Android 2.1 OS and what I had to do to overcome the problem.&lt;br /&gt;&lt;br /&gt;The other day, I was trying to perform some animation when the input field gets focus . Let me be specific. I have a text input field and when it gets focus, I want to move the input field towards the left as shown in figure. After the animation is complete, I want to run some validation logic once the user submits the form.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_bzJH8WMGhDA/TSqkPtQLIQI/AAAAAAAAC10/EU1ONXdtbPI/s1600/field%2Bstate.png"&gt;&lt;img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;width: 320px; height: 277px;" src="http://2.bp.blogspot.com/_bzJH8WMGhDA/TSqkPtQLIQI/AAAAAAAAC10/EU1ONXdtbPI/s320/field%2Bstate.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5560437279694725378" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;pre class="brush:css"&gt;&amp;lt;style&gt;&lt;br /&gt;  .normal{margin-left: 50px;}&lt;br /&gt;  .animate{margin-left: 0px;-webkit-transition: all 0.3s ease-out; }&lt;br /&gt;&amp;lt;/style&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre class="brush:html"&gt;&amp;lt;div id="sb" class="normal"&gt;&lt;br /&gt;  &amp;lt;form&gt;&lt;br /&gt;    &amp;lt;input id="q" name="q" type="text" value="flowers" onfocus="OnFocusEventHandler(event);"/&gt;&lt;br /&gt;  &amp;lt;/form&gt;&lt;br /&gt;&amp;lt;/div&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre class="brush:js"&gt;function OnFocusEventHandler(e)&lt;br /&gt;{&lt;br /&gt;   var ele = $("sb");       &lt;br /&gt;   ele.className = "animate";&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style:italic;"&gt;OnFocusEventHandler&lt;/span&gt; changed the css class of the input field container which essentially performed the animation. This worked so far. As I mentioned in one of my &lt;a href="http://jjalan.blogspot.com/2011/01/html-form-validation-on-webkit-mobile.html"&gt;previous blog post&lt;/a&gt;, I hooked up the validation logic to &lt;span style="font-style:italic;"&gt;keydown&lt;/span&gt; event of the input field. But to my surprise, when the user tapped on "return" key on the keyboard, the &lt;span style="font-weight:bold;"&gt;&lt;span style="font-style:italic;"&gt;keydown&lt;/span&gt; event handler never got fired&lt;/span&gt; ! &lt;span style="font-weight:bold;"&gt;Browser also didn't fire submit event on the form&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;To debug the problem, I tried animating the input field by clicking on a button, putting focus on input field manually by tapping on it and then submitting the form by hitting the "return" key. This time everything worked fine - keydown event handler got called and the validation logic ran just fine. I also tried attaching the animation logic to mousedown / touchend events of the field but met with no success. With some more experimentation, I found that if I move the input element as soon as it gets focus (and at the same time browser brings up the virtual keyboard), the keyboard events are not properly attached to the input field. &lt;br /&gt;&lt;br /&gt;Then I tried the obvious thing - I waited for sometime after onfocus event to begin the animation by using Window.setTimeout. And that did the trick. I set the delay of 500 ms (100, 200 ms etc didn't solve the problem) before I started the animation. Essentially I had to wait for the keyboard to become visible completely before I can start the animation.&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:js"&gt;function OnFocusEventHandler(e)&lt;br /&gt;{&lt;br /&gt;   window.setTimeout(function()&lt;br /&gt;   {&lt;br /&gt;     var ele = $("sb");       &lt;br /&gt;     ele.className = "animate";&lt;br /&gt;    }, 500);&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;I was hoping that a very simple thing like this would just work out of the box. But it didn't. Sad Web Developer :(.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/14059684-7209207972297121649?l=jjalan.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jjalan.blogspot.com/feeds/7209207972297121649/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=14059684&amp;postID=7209207972297121649' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/14059684/posts/default/7209207972297121649'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/14059684/posts/default/7209207972297121649'/><link rel='alternate' type='text/html' href='http://jjalan.blogspot.com/2011/01/enter-keyboard-event-with-animation-on.html' title='Enter keyboard event with animation on Samsung sch-i400'/><author><name>Jaikishan Jalan</name><uri>http://www.blogger.com/profile/04104646893980850789</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://3.bp.blogspot.com/_bzJH8WMGhDA/TSlpIO8rRhI/AAAAAAAAC1Q/SmCsqbro818/S220/114.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_bzJH8WMGhDA/TSqkPtQLIQI/AAAAAAAAC10/EU1ONXdtbPI/s72-c/field%2Bstate.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-14059684.post-2103332849155617842</id><published>2011-01-09T01:09:00.000-08:00</published><updated>2011-02-04T20:06:35.278-08:00</updated><title type='text'>Backspace event on input fields</title><content type='html'>As a part of my job, I had to write code which would do something when the user hits the backspace on an input field (type=text). At first glance, this looked like a piece of cake. I listened to &lt;span style="font-style:italic;"&gt;keydown&lt;/span&gt; event of input field and invoked the logic when the event keycode is 8 (browser sets the keycode of the event to 8 on backspace).&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:js"&gt;function OnKeyDownEventHandler(e)&lt;br /&gt;{&lt;br /&gt;   if(e===null) e=window.event;&lt;br /&gt;   if(e!= null &amp;&amp; typeof e != 'undefined')&lt;br /&gt;   {&lt;br /&gt;       if(e.keyCode===8)&lt;br /&gt;       {&lt;br /&gt;           // That means user tapped on backspace&lt;br /&gt;           // Run your logic here&lt;br /&gt;       }&lt;br /&gt;   }&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;This logic ran smoothly on all the different versions of iOS (iPhone and iPod). But this logic would fail on iphone 3 and lower devices &lt;span style="font-weight:bold;"&gt;when the value of the input field is empty&lt;/span&gt;. In that case, for some reason, browser would fire event with keycode as 127 and that too multiple times ! So, I had to make sure that I would listen for event with keycode of 127 and also had to make sure that I invoke my logic only once by maintaining a boolean flag. Also note that some android devices, for example, Samsung Focus (Android 2.1 and I think on 2.2 also) &lt;span style="font-weight:bold;"&gt;would not fire any event&lt;/span&gt; when the value of the input field is empty and user hits backspace. There were some other android devices which had the similar.&lt;br /&gt;&lt;br /&gt;In short, you would expect simple things like this would work on atleast webkit browsers on mobile devices but sadly it does not. Make sure you know which devices you are going to support for your application and test your logic on those devices ( running on different versions of OS too, my experience tells me that Android 2.2 is well behaved than Android 2.1) and test your application with extensive test cases.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/14059684-2103332849155617842?l=jjalan.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jjalan.blogspot.com/feeds/2103332849155617842/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=14059684&amp;postID=2103332849155617842' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/14059684/posts/default/2103332849155617842'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/14059684/posts/default/2103332849155617842'/><link rel='alternate' type='text/html' href='http://jjalan.blogspot.com/2011/01/backspace-event-on-input-fields.html' title='Backspace event on input fields'/><author><name>Jaikishan Jalan</name><uri>http://www.blogger.com/profile/04104646893980850789</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://3.bp.blogspot.com/_bzJH8WMGhDA/TSlpIO8rRhI/AAAAAAAAC1Q/SmCsqbro818/S220/114.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-14059684.post-86514022959973942</id><published>2011-01-08T23:58:00.000-08:00</published><updated>2011-02-04T20:06:09.880-08:00</updated><title type='text'>Html form validation on a webkit mobile browser</title><content type='html'>In this post, I am going to talk about how can we run validation logic on form fields on mobile webkit browser and stop it from being submitted if the validation fails and submit it if the validation passes. It is well known that if the browser/ or your javascript code has invoked the submit event on the form, it is too late to run the validation logic i.e. you can never stop the browser to submit the form if the validation logic fails. Even if you try to set the return value of the event to false or if you try to stop default action from submit event handler. I always use the following method to kill an event&lt;br /&gt;&lt;br /&gt;&lt;pre class='brush: js'&gt; // e: Event&lt;br /&gt;function stopEvent(e)&lt;br /&gt;{&lt;br /&gt;  if(e===null) e = window.event;&lt;br /&gt;  if(e!=null &amp;&amp; typeof e != 'undefined')&lt;br /&gt;  {&lt;br /&gt;   e.cancelBubble = true;&lt;br /&gt;   e.returnValue = false;&lt;br /&gt;   if (e.stopPropagation) {e.stopPropagation();};&lt;br /&gt;   if (e.preventDefault) {e.preventDefault();};&lt;br /&gt;  }&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;On mobile devices, user would submit a form by hitting "Go" or "Search" button on iPhone or "return" button on Android unless you have your own submit button on the page. When the user hits the button, browser would fire the submit event on the form and if you call &lt;span style="font-style:italic;"&gt;stopEvent&lt;/span&gt; method from your form submit event handler, the browser would still submit the form. So in order to solve the problem, we need to get hold of an event that browser fires before it fires submit event on the form. If we can find such an event, then we can run the validation logic in that event handler and stop bubbling of the event if the validation logic fails. In that case, submit event would never be triggered on the form and we will achieve our goal.&lt;br /&gt;&lt;br /&gt;In my case, I have an input field (type=text) and for discussion purpose, I just want to make sure that the value in input field is not empty. The way I solved this problem is by running the validation logic in &lt;span style="font-style:italic;"&gt;keydown&lt;/span&gt; event handler of the field. When the user taps on "Go" or "return" button on the phone, browser sets the event keycode to 13. So assuming &lt;span style="font-style:italic;"&gt;OnKeyDownEventHandler&lt;/span&gt; is your event handler for keydown event, you can do the following:&lt;br /&gt;&lt;br /&gt;&lt;pre class='brush: js'&gt;function OnKeyDownEventHandler(e)&lt;br /&gt;{&lt;br /&gt;   if(e===null)e=window.event;&lt;br /&gt;   if(e!=null &amp;&amp; typeof e != 'undefined')&lt;br /&gt;   {&lt;br /&gt;       var keycode = e.keyCode;&lt;br /&gt;       if(keycode===13)&lt;br /&gt;       { &lt;br /&gt;           // IsValid runs the validation logic &lt;br /&gt;           if(!IsValid())&lt;br /&gt;              stopEvent(e);&lt;br /&gt;       }     &lt;br /&gt;   }&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;Note that on iPhone 3 (not sure below iphone 3), browser sets the keycode to 10 instead of 13. So you to make this logic work on iphone 3 and above, you need to run the logic when the keycode is also 10.&lt;br /&gt;&lt;br /&gt;&lt;pre class='brush: js'&gt;function OnKeyDownEventHandler(e)&lt;br /&gt;{&lt;br /&gt;   if(e===null)e=window.event;&lt;br /&gt;   if(e!=null &amp;&amp; typeof e != 'undefined')&lt;br /&gt;   {&lt;br /&gt;       var keycode = e.keyCode;&lt;br /&gt;       if(keycode===13 || keycode===10)&lt;br /&gt;       { &lt;br /&gt;           // IsValid runs the validation logic &lt;br /&gt;           if(!IsValid())&lt;br /&gt;              stopEvent(e);&lt;br /&gt;       }     &lt;br /&gt;   }&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;Some might argue that other browsers might fire keycode 10 for a different key and this would break the logic. True. But practically I have never came across such a situation. If you want, you can do device sniffing by getting the UA and running the logic for keycode = 10 only if the device is iphone with version 3.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/14059684-86514022959973942?l=jjalan.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jjalan.blogspot.com/feeds/86514022959973942/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=14059684&amp;postID=86514022959973942' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/14059684/posts/default/86514022959973942'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/14059684/posts/default/86514022959973942'/><link rel='alternate' type='text/html' href='http://jjalan.blogspot.com/2011/01/html-form-validation-on-webkit-mobile.html' title='Html form validation on a webkit mobile browser'/><author><name>Jaikishan Jalan</name><uri>http://www.blogger.com/profile/04104646893980850789</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://3.bp.blogspot.com/_bzJH8WMGhDA/TSlpIO8rRhI/AAAAAAAAC1Q/SmCsqbro818/S220/114.JPG'/></author><thr:total>0</thr:total></entry></feed>
