﻿<?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>Girish Gangadharan &#187; Javascript</title>
	<atom:link href="http://giri.sh/wp-404-handler.php/category/javascript/feed/?404;http://giri.sh:80/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://giri.sh</link>
	<description>Did you expect something witty here?</description>
	<lastBuildDate>Mon, 26 Jul 2010 20:35:59 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Overriding hyperlinks&#8217; default behaviour in javascript</title>
		<link>http://giri.sh/2006/07/06/overriding-hyperlinks-default-behaviour-in-javascript/</link>
		<comments>http://giri.sh/2006/07/06/overriding-hyperlinks-default-behaviour-in-javascript/#comments</comments>
		<pubDate>Fri, 07 Jul 2006 03:14:00 +0000</pubDate>
		<dc:creator>girish</dc:creator>
				<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://morethan2cents.com/morethan2cents/?p=18</guid>
		<description><![CDATA[No biggie, right? Write a javascript function that should do whatever is needed and just hook it up with the OnClick attribute of the hyperlink. Simple and easy.
Let&#8217;s say the function looks something like this.
&#60;script  type="text/javascript"&#62;function HandleClick() {
alert("Some message!");
}
&#60;/script&#62;
Now let&#8217;s test it.
function HandleClick() {
alert("Some message!");
}

Click this link.
See what happened? The javascript function was executed [...]]]></description>
			<content:encoded><![CDATA[<p>No biggie, right? Write a javascript function that should do whatever is needed and just hook it up with the OnClick attribute of the hyperlink. Simple and easy.</p>
<p>Let&#8217;s say the function looks something like this.</p>
<p><code>&lt;script  type="text/javascript"&gt;function HandleClick() {<br />
alert("Some message!");<br />
}<br />
&lt;/script&gt;</code></p>
<p>Now let&#8217;s test it.</p>
<p><script  type="text/javascript">function HandleClick() {
alert("Some message!");
}
</script></p>
<p>Click this <a onclick="HandleClick();" href="http://www.morethan2cents.com">link</a>.</p>
<p>See what happened? The javascript function was executed but you still got redirected to the url set in the <code>href</code> attribute of the link.</p>
<p>This is due to the fact that we have overridden the default behaviour of the hyperlink but we still haven&#8217;t told Javascript to cancel the default behaviour.</p>
<p>How do we fix this? Just add <code>return false;</code> right after the function call, as shown below.</p>
<p><code>&lt;a href="http://www.morethan2cents.com" onclick="HandleClick(); return false;"&gt;link&lt;/a&gt;</code></p>
<p>By returning false, you are basically telling javascript that the link was not clicked and thus not to trigger the default behaviour.</p>
<p>Now try it again.  Click this <a onclick="HandleClick(); return false;" href="http://www.morethan2cents.com"> link</a>.</p>
<p>Voila! No redirection. Alternatively, you could leave the href attribute blank (<code>href=&#8221;&#8221;</code>). But that would basically refresh the page for obvious reasons.</p>
]]></content:encoded>
			<wfw:commentRss>http://giri.sh/2006/07/06/overriding-hyperlinks-default-behaviour-in-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Smart navigation alternative</title>
		<link>http://giri.sh/2006/05/23/smart-navigation-alternative/</link>
		<comments>http://giri.sh/2006/05/23/smart-navigation-alternative/#comments</comments>
		<pubDate>Wed, 24 May 2006 01:37:00 +0000</pubDate>
		<dc:creator>girish</dc:creator>
				<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://morethan2cents.com/morethan2cents/?p=8</guid>
		<description><![CDATA[So in this project that i&#8217;m working on at my workplace, we have a bunch of products&#8217; details displayed in a grid whose prices can be overridden by the admin user. The user has to check a &#8220;Override&#8221; checkbox, which would enable the price textbox. Uncheck obviously means the price cannot be overridden and textbox [...]]]></description>
			<content:encoded><![CDATA[<p>So in this project that i&#8217;m working on at my workplace, we have a bunch of products&#8217; details displayed in a grid whose prices can be overridden by the admin user. The user has to check a &#8220;Override&#8221; checkbox, which would enable the price textbox. Uncheck obviously means the price cannot be overridden and textbox would be disabled. For business reasons, we had to use the autopostback option for the override checkboxes.</p>
<p>Anyways&#8230;the challenge was that there were atleast 25 or more products displayed in the grid and thus as you can imagine, when the user checked the bottom most product&#8217;s override checkbox the page posted back and auto-scrolled to the top of the page. This could be very annoying to the user and apparently, Smart Navigation was neither smart nor navigated anywhere expected and forced me to rely on Javascript to solve this issue.</p>
<p>After some googling, here&#8217;s how i fixed it.</p>
<p>There&#8217;s a javascript property called <em>location.hash</em></p>
<p>bq. hash is a property of both the Link and the Location objects and is a string beginning with a hash (#). It specifies an anchor name in an HTTP URL.</p>
<p>For example, if the url is something like http://www.example.com#anchor</p>
<p>then #anchor is the hash property.</p>
<p>What this means is that if you have the id of an element in the page, you can set the focus to that element, when the page loads by using the location.hash property.</p>
<p>If you are using the <a href="http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/a.asp"><em>a element</em></a> , then you may use either the id attribute or the name attribute.</p>
<p>So i wrote a little procedure in the aspx&#8217;s code-behind that looks like this:</p>
<pre>Private Sub anchorScript(ByVal productId As String)
     Dim Script As String
     Script &amp;= "" &amp; Environment.NewLine
     Script &amp;= "var anchorLocation='#" &amp; productId &amp; "';" &amp; Environment.NewLine
     Script &amp;= "location.hash=anchorLocation;" &amp; Environment.NewLine
     Script &amp;= "" &amp; Environment.NewLine

     If (Not Page.IsStartupScriptRegistered("anchorScript")) Then
           Page.RegisterStartupScript("anchorScript", Script)
     End If
End Sub</pre>
<p>And called this procedure after doing the necessary stuff in the checkbox&#8217;s CheckedChanged event handler. Typically this would be the last line in the sub.</p>
<p>The above procedure registers a javascript function that when rendered, would look like this :</p>
<pre>
var anchorLocation='#'
location.hash=anchorLocation;
</pre>
<p>This would tell the browser to focus on the element that has an id(passed into the anchorScript procedure).</p>
<p>Simple. Worked like a charm.</p>
]]></content:encoded>
			<wfw:commentRss>http://giri.sh/2006/05/23/smart-navigation-alternative/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
