<?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>Chris: Geek Guy &#187; getelementbyid</title>
	<atom:link href="http://chris.gg/tag/getelementbyid/feed/" rel="self" type="application/rss+xml" />
	<link>http://chris.gg</link>
	<description>Tech news and other stuff from a UK-based web developer and all-round geek</description>
	<lastBuildDate>Tue, 06 Dec 2011 19:40:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>SharePoint and getElementById()</title>
		<link>http://chris.gg/2010/02/sharepoint-and-getelementbyid/</link>
		<comments>http://chris.gg/2010/02/sharepoint-and-getelementbyid/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 15:18:17 +0000</pubDate>
		<dc:creator>Chris Barnes</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[getelementbyid]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[sharepoint]]></category>
		<guid isPermaLink="false">http://chris.gg/?p=624</guid>
		<description><![CDATA[I&#8217;ve just found out that using JavaScript&#8217;s getElementById() function doesn&#8217;t quite work as expected when dealing with controls on SharePoint pages. This is because SharePoint uses its own identifiers, so TextBox1 becomes something like ctl00$ctl00$g_3f6d90e4_335b_467c_a53f_6ae00bca6b63$ctl00$TextBox1. Fortunately there&#8217;s a simple solution &#8211; instead of the following (which will cause an &#8220;Object required&#8221; JavaScript error): document.getElementById("TextBox1"); you need [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just found out that using JavaScript&#8217;s <strong>getElementById()</strong> function doesn&#8217;t quite work as expected when dealing with controls on SharePoint pages. This is because SharePoint uses its own identifiers, so <strong>TextBox1 </strong> becomes something like <strong>ctl00$ctl00$g_3f6d90e4_335b_467c_a53f_6ae00bca6b63$ctl00$TextBox1</strong>.</p>
<p>Fortunately there&#8217;s a simple solution &#8211; instead of the following (which will cause an &#8220;Object required&#8221; JavaScript error):</p>
<pre lang="csharp">document.getElementById("TextBox1");</pre>
<p>you need to use this, which will insert the correct full ID for the element and thus work correctly:</p>
<pre lang="csharp">document.getElementById("< %=TextBox1.ClientID%>");</pre>
<p>It gets a bit more complicated when using nested controls, which is explained in <a href="http://www.binarywave.com/blogs/eshupps/Lists/Posts/Post.aspx?List=9c93c708-e5ce-4714-bdea-499330361130&amp;ID=23">this post by Eric Shupps</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://chris.gg/2010/02/sharepoint-and-getelementbyid/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

