<?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>moopoo.net &#187; jQuery</title>
	<atom:link href="http://moopoo.net/tag/jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://moopoo.net</link>
	<description>Fishing, technology and anything else</description>
	<lastBuildDate>Wed, 09 Jun 2010 11:34:08 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Highlighting row on form error with jQuery</title>
		<link>http://moopoo.net/web-development/jquery/highlighting-row-on-form-error-with-jquery/</link>
		<comments>http://moopoo.net/web-development/jquery/highlighting-row-on-form-error-with-jquery/#comments</comments>
		<pubDate>Mon, 18 May 2009 08:34:32 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://moopoo.net/?p=75</guid>
		<description><![CDATA[When showing errors in web forms, I thought it would be useful to highlight the row where the error occurred so the user can visually see where they they need to make changes. jQuery is the ideal way to do this for me as I didn&#8217;t want to do it server side.
To begin I set [...]]]></description>
			<content:encoded><![CDATA[<p>When showing errors in web forms, I thought it would be useful to highlight the row where the error occurred so the user can visually see where they they need to make changes. jQuery is the ideal way to do this for me as I didn&#8217;t want to do it server side.</p>
<p>To begin I set a CSS class on the error messages that were displayed in the td with the form element. An error message could be in the form of</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;span class=&quot;.valError&quot;&gt;You have selected an invalid date.&lt;/span&gt;</pre></div></div>

<p>Now all we have to do in jQuery is find all elements which match the class, remove any classes that may be on any of the td tags, then add a class to the tr in which the error exists.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.valError&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// remove all classes from any td's of the below the parent row</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;td&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #006600; font-style: italic;">// set the class on the tr</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'ms-informationbar'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>That&#8217;s it.</p>
<p>You could optionally set the class of the td rather than or as well as the tr. The following line would help you achieve this.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;td&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'myErrorClass'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://moopoo.net/web-development/jquery/highlighting-row-on-form-error-with-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
