
<?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>jtGraphic.net &#187; dhtml</title>
	<atom:link href="http://jtgraphic.net/tag/dhtml/feed/" rel="self" type="application/rss+xml" />
	<link>http://jtgraphic.net</link>
	<description></description>
	<lastBuildDate>Fri, 03 Feb 2012 01:15:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Using Javascript for Commenting in Inputs</title>
		<link>http://jtgraphic.net/javascript-commenting-inputs/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=javascript-commenting-inputs</link>
		<comments>http://jtgraphic.net/javascript-commenting-inputs/#comments</comments>
		<pubDate>Thu, 08 Jan 2009 07:06:35 +0000</pubDate>
		<dc:creator>jt</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[comments]]></category>
		<category><![CDATA[dhtml]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[Shoemoney]]></category>

		<guid isPermaLink="false">http://www.jtgraphic.net/?p=188</guid>
		<description><![CDATA[<p>Tweet You can use Javascript to build inline comments for your input fields.  This is a great way to denote required fields and pre-populate data.  If you&#8217;re using this script to show comments on required fields, I would suggest combining &#8230; <a href="http://jtgraphic.net/javascript-commenting-inputs/">Continue reading <span class="meta-nav">&#8594;</span></a></p><p>Originally posted on jtGraphic.net: <a href="http://jtgraphic.net/javascript-commenting-inputs/">Using Javascript for Commenting in Inputs</a></p>]]></description>
			<content:encoded><![CDATA[<div class="bottomcontainerBox" style="">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fjtgraphic.net%2Fjavascript-commenting-inputs%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://jtgraphic.net/javascript-commenting-inputs/"></g:plusone>
			</div>
			<div style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://jtgraphic.net/javascript-commenting-inputs/"  data-text="Using Javascript for Commenting in Inputs" data-count="horizontal" data-via="jtgraphic">Tweet</a>
			</div><div style="float:left; width:105px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://jtgraphic.net/javascript-commenting-inputs/" data-counter="right"></script></div>			
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://jtgraphic.net/javascript-commenting-inputs/"></script></div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div><p>You can use Javascript to build inline comments for your input fields.  This is a great way to denote required fields and pre-populate data.  If you&#8217;re using this script to show comments on required fields, I would suggest combining it with some sort of server or client side validation script &#8211; or both.  The code is an example SIMILAR to the way WordPress&#8217;s comments form looks.  Some day I will build a widget for this.</p>
<h3>The Code</h3>
<pre>&lt;h4&gt;Leave a Reply&lt;/h4&gt;
&lt;form action="action.php" method="post" id="commentform"&gt;
  &lt;div class="inputs"&gt;
    &lt;input type="text" name="author" id="author"
      onClick="removeTextCheck(this,'(Required)');"
      onBlur="addTextCheck(this,'(Required)');"
      value="(Required)" /&gt;
    &lt;input type="text" name="email" id="email"
      onClick="removeTextCheck(this,'(Required)');"
      onBlur="addTextCheck(this,'(Required)');"
      value="(Required)" /&gt;
    &lt;input type="text" name="url" id="url" value="" /&gt;
  &lt;/div&gt;
  &lt;textarea name="comment" id="comment"
    onClick="removeTextCheck(this,'(Your Message)');"
    onBlur="addTextCheck(this,'(Your Message)');"&gt;(Your Message)&lt;/textarea&gt;
&lt;/form&gt;
&lt;script type="text/javascript"&gt;
  function removeTextCheck(element,initialValue) {
    if(element.value == initialValue) element.value = "";
  }

  function addTextCheck(element,initialValue) {
    if(element.value == "") element.value = initialValue;
  }
&lt;/script&gt;</pre>
<h3>Explanation</h3>
<p>This code is actually pretty simple.  For each element that you wish to do an inline comment for, you&#8217;ll need an &#8220;onClick&#8221; even and an &#8220;onBlur&#8221; event.  For the &#8220;onClick&#8221; event you&#8217;ll create a function called &#8220;removeTextCheck&#8221; and call it in each input or text area that you&#8217;d like to leave an inline comment for.  For the &#8220;onBlur&#8221; event, you&#8217;ll create a function called &#8220;addTextCheck&#8221; and call it in each input or text area that you&#8217;d like to leave an inline comment for.</p>
<p>Both functions have two arguments: &#8220;element&#8221; and &#8220;initialValue&#8221; which have pretty much the same definition in both functions.  The &#8220;element&#8221; argument is the element in which you are placing the inline comment.  You will always use the &#8220;this&#8221; variable when calling this function inline.  If you call it from somewhere else in your page you may want to use something like &#8220;getElementById&#8221; or something similar.  The second argument &#8220;initialValue&#8221; will be the value that you wish to check against for adding/removing the text.  In my code above, that was either the &#8220;(Required)&#8221; values or the &#8220;(Your Message)&#8221; value.  You will want to make sure that this argument matches the value attribute of either your input or textarea.</p>
<p>Did this make sense to you?  Let me know!</p>
<p>Oh, and the code above can be copied and pasted as is into a blank text document to creat a working page.</p>
<div class="bottomcontainerBox" style="">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fjtgraphic.net%2Fjavascript-commenting-inputs%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://jtgraphic.net/javascript-commenting-inputs/"></g:plusone>
			</div>
			<div style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://jtgraphic.net/javascript-commenting-inputs/"  data-text="Using Javascript for Commenting in Inputs" data-count="horizontal" data-via="jtgraphic">Tweet</a>
			</div><div style="float:left; width:105px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://jtgraphic.net/javascript-commenting-inputs/" data-counter="right"></script></div>			
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://jtgraphic.net/javascript-commenting-inputs/"></script></div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div><p>Originally posted on jtGraphic.net: <a href="http://jtgraphic.net/javascript-commenting-inputs/">Using Javascript for Commenting in Inputs</a></p>]]></content:encoded>
			<wfw:commentRss>http://jtgraphic.net/javascript-commenting-inputs/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

