[jQuery] Code simplifying request.
<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:st1="urn:schemas-microsoft-com:office:smarttags" xmlns="http://www.w3.org/TR/REC-html40"
xmlns:ns0="urn:schemas-microsoft-com:office:smarttags">
<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 11 (filtered medium)">
<!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]--><o:SmartTagType
namespaceuri="urn:schemas-microsoft-com:office:smarttags" name="Street"/>
<o:SmartTagType namespaceuri="urn:schemas-microsoft-com:office:smarttags"
name="PlaceType"/>
<o:SmartTagType namespaceuri="urn:schemas-microsoft-com:office:smarttags"
name="PlaceName"/>
<o:SmartTagType namespaceuri="urn:schemas-microsoft-com:office:smarttags"
name="address"/>
<o:SmartTagType namespaceuri="urn:schemas-microsoft-com:office:smarttags"
name="State"/>
<o:SmartTagType namespaceuri="urn:schemas-microsoft-com:office:smarttags"
name="City"/>
<o:SmartTagType namespaceuri="urn:schemas-microsoft-com:office:smarttags"
name="place"/>
<o:SmartTagType namespaceuri="urn:schemas-microsoft-com:office:smarttags"
name="PersonName"/>
<!--[if !mso]>
<style>
st1\:*{behavior:url(#default#ieooui) }
</style>
<![endif]-->
<style>
<!--
/* Font Definitions */
@font-face
{font-family:"Monotype Corsiva";
panose-1:3 1 1 1 1 2 1 1 1 1;}
@font-face
{font-family:Tahoma;
panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
{font-family:Verdana;
panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
{font-family:"Trebuchet MS";
panose-1:2 11 6 3 2 2 2 2 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman";}
p.MsoEnvelopeAddress, li.MsoEnvelopeAddress, div.MsoEnvelopeAddress
{margin-top:0in;
margin-right:0in;
margin-bottom:0in;
margin-left:2.0in;
margin-bottom:.0001pt;
mso-element:frame;
font-size:14.0pt;
font-family:"Monotype Corsiva";
font-weight:bold;
font-style:italic;}
p.MsoEnvelopeReturn, li.MsoEnvelopeReturn, div.MsoEnvelopeReturn
{margin:0in;
margin-bottom:.0001pt;
font-size:10.0pt;
font-family:"Monotype Corsiva";
font-style:italic;}
a:link, span.MsoHyperlink
{color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{color:blue;
text-decoration:underline;}
p
{mso-margin-top-alt:auto;
margin-right:0in;
mso-margin-bottom-alt:auto;
margin-left:0in;
font-size:12.0pt;
font-family:"Times New Roman";}
span.EmailStyle20
{mso-style-type:personal-reply;
font-family:Verdana;
color:black;
font-weight:normal;
font-style:normal;
text-decoration:none none;}
@page Section1
{size:8.5in 11.0in;
margin:1.0in 1.25in 1.0in 1.25in;}
div.Section1
{page:Section1;}
-->
</style>
</head>
<body lang=EN-US link=blue vlink=blue>
<div class=Section1>
<p class=MsoNormal><font size=2 face="Trebuchet MS"><span style='font-size:
10.0pt;font-family:"Trebuchet MS"'>You don’t need the elements in the
selector (i.e. form / input). The fastest way to select is on the unique id. <o:p></o:p></span></font>
<p class=MsoNormal><font size=2 face="Trebuchet MS"><span style='font-size:
10.0pt;font-family:"Trebuchet MS"'><o:p> </o:p></span></font>
<p class=MsoNormal><font size=2 face="Trebuchet MS"><span style='font-size:
10.0pt;font-family:"Trebuchet MS"'>Also, instead of calling the same jQuery
selector over and over set it to a local variable. <o:p></o:p></span></font>
<p class=MsoNormal><font size=2 face="Trebuchet MS"><span style='font-size:
10.0pt;font-family:"Trebuchet MS"'><o:p> </o:p></span></font>
<p class=MsoNormal><font size=2 face="Trebuchet MS"><span style='font-size:
10.0pt;font-family:"Trebuchet MS"'>$('#checkout').submit( function(){
// if field
has something in it, do submit actions, otherwise write out error
var a = $('#rxt_forename');<o:p></o:p></span></font>
<p class=MsoNormal style='text-indent:.5in'><font size=2 face="Trebuchet MS"><span
style='font-size:10.0pt;font-family:"Trebuchet MS"'>if(a.val() == '' ){
// add class
to change colour
a.addClass("required").get(0).focus();
a.siblings("span.error").show();
return
false;
}else{
a.removeClass("required");
a.siblings("span.error").hide();
}</span></font><font
size=2 color=black face=Verdana><span style='font-size:10.0pt;font-family:Verdana;
color:black'><o:p></o:p></span></font>
<p class=MsoNormal><font size=2 color=black face=Verdana><span
style='font-size:10.0pt;font-family:Verdana;color:black'><o:p> </o:p></span></font>
<div>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><b><font
size=2 face=Verdana><span style='font-size:10.0pt;font-family:Verdana;
font-weight:bold'><ns0:PersonName w:insAuthor="David Dexter"
w:insDate="2007-03-21T09:50:00Z" w:endInsAuthor="David Dexter"
w:endInsDate="2007-03-21T09:50:00Z"><ns0:PersonName w:insAuthor="David Dexter"
w:insDate="2007-03-21T09:50:00Z" w:endInsAuthor="David Dexter"
w:endInsDate="2007-03-21T09:50:00Z"><st1:PersonName w:st="on"><font
color="#336699"><span style='color:#336699'>David Dexter</span></font></st1:PersonName></ns0:PersonName></u2:PersonName><font
color=silver><span style='color:silver'> |
brilliantlemming.com | </span></font><ns0:place
w:insAuthor="David Dexter" w:insDate="2007-03-21T09:50:00Z"
w:endInsAuthor="David Dexter" w:endInsDate="2007-03-21T09:50:00Z"><ns0:City
w:insAuthor="David Dexter" w:insDate="2007-03-21T09:50:00Z"
w:endInsAuthor="David Dexter" w:endInsDate="2007-03-21T09:50:00Z"><st1:place
w:st="on"><st1:City w:st="on"><font color=silver><span style='color:silver'>Brentwood</span></font></st1:City></ns0:City></st1:place><font
color=silver><span style='color:silver'>, </span></font><ns0:State
w:insAuthor="David Dexter" w:insDate="2007-03-21T09:50:00Z"
w:endInsAuthor="David Dexter" w:endInsDate="2007-03-21T09:50:00Z"><st1:State
w:st="on"><font color=silver><span style='color:silver'>CA</span></font></st1:State></ns0:State></ns0:place><font
color=silver><span style='color:silver'> | 310.414.0949</span></font></ns0:PersonName></span></font></b><b><font
size=2 color=silver face=Verdana><span style='font-size:10.0pt;font-family:
Verdana;color:silver;font-weight:bold'><o:p></o:p></span></font></b>
</div>
<div>
<div class=MsoNormal align=center style='text-align:center'><font size=3
face="Times New Roman"><span style='font-size:12.0pt'>
<hr size=2 width="100%" align=center tabindex=-1>
</span></font></div>
<p class=MsoNormal><b><font size=2 face=Tahoma><span style='font-size:10.0pt;
font-family:Tahoma;font-weight:bold'>From:</span></font></b><font size=2
face=Tahoma><span style='font-size:10.0pt;font-family:Tahoma'> discuss-bounces@jquery.com
[mailto:discuss-bounces@jquery.com] <b><span style='font-weight:bold'>On Behalf
Of </span></b>Luc Pestille
<b><span style='font-weight:bold'>Sent:</span></b> Wednesday, March 21, 2007
9:40 AM
<b><span style='font-weight:bold'>To:</span></b> jQuery Discussion.
<b><span style='font-weight:bold'>Subject:</span></b> [jQuery] Code simplifying
request.</span></font><o:p></o:p>
</div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'><o:p> </o:p></span></font>
<div>
<table class=MsoNormalTable border=0 cellspacing=0 cellpadding=0>
<tr>
<td style='padding:0in 0in 0in 0in'>
<p class=MsoNormal><font size=3 face="Times New Roman"><span
style='font-size:12.0pt'><o:p> </o:p></span></font>
</td>
<td style='padding:0in 0in 0in 0in'>
<div>
<p class=MsoNormal><font size=2 face="Trebuchet MS"><span style='font-size:
10.0pt;font-family:"Trebuchet MS"'>Hi all,</span></font><o:p></o:p>
</div>
<div>
<p class=MsoNormal><font size=2 face="Trebuchet MS"><span style='font-size:
10.0pt;font-family:"Trebuchet MS"'>I've got some simple validation to do (not
enough to use one of the form plugins), and have this;</span></font><o:p></o:p>
</div>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span
style='font-size:12.0pt'> <o:p></o:p></span></font>
</div>
<div>
<p class=MsoNormal><font size=2 face="Trebuchet MS"><span style='font-size:
10.0pt;font-family:"Trebuchet MS"'>// when the form is submitted
$('form#checkout').submit( function(){
// if field has something in it, do submit actions,
otherwise write out error
if( $('input#rxt_forename').val() == '' ){
// add class to change colour
$('input#rxt_forename').addClass("required").get(0).focus();
$('input#rxt_forename').siblings("span.error").show();
return false;
}else{
$('input#rxt_forename').removeClass("required");
$('input#rxt_forename').siblings("span.error").hide();
}</span></font><o:p></o:p>
</div>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span
style='font-size:12.0pt'> <o:p></o:p></span></font>
</div>
<div>
<p class=MsoNormal><font size=2 face="Trebuchet MS"><span style='font-size:
10.0pt;font-family:"Trebuchet MS"'>How can i simplify it? I would have
thought replacing the input selector with $(this) would work, but it doesn't,
and I'm sure the class/siblings processes could be chained...</span></font><o:p></o:p>
</div>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span
style='font-size:12.0pt'> <o:p></o:p></span></font>
</div>
<div>
<p class=MsoNormal><font size=2 face="Trebuchet MS"><span style='font-size:
10.0pt;font-family:"Trebuchet MS"'>Thanks,</span></font><o:p></o:p>
</div>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span
style='font-size:12.0pt'> <o:p></o:p></span></font>
</div>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span
style='font-size:12.0pt'> <o:p></o:p></span></font>
</div>
<table class=MsoNormalTable border=0 cellpadding=0 align=left>
<tr>
<td valign=top style='padding:.75pt .75pt .75pt .75pt'>
<p class=MsoNormal><font size=3 face="Times New Roman"><span
style='font-size:12.0pt'><img width=30 height=33 id="_x0000_i1025"
src="cid:image001.gif@01C76B9E.E7DC7CA0"><o:p></o:p></span></font>
</td>
<td width=10 style='width:.1in;padding:.75pt .75pt .75pt .75pt'>
<p class=MsoNormal><font size=3 face="Times New Roman"><span
style='font-size:12.0pt'><o:p> </o:p></span></font>
</td>
<td valign=top style='padding:.75pt .75pt .75pt .75pt'>
<b><font size=2 face="Trebuchet MS"><span style='font-size:10.0pt;
font-family:"Trebuchet MS";font-weight:bold'>Luc Pestille</span></font></b><font
size=2 face="Trebuchet MS"><span style='font-size:10.0pt;font-family:"Trebuchet MS"'>
Web Designer <o:p></o:p></span></font>
<font size=2 face="Trebuchet MS"><span style='font-size:10.0pt;
font-family:"Trebuchet MS"'>e: luc.pestille@in2.co.uk
t: +44 (0)1628 899 700
f: +44 (0)1628 899 701 <o:p></o:p></span></font>
</td>
</tr>
</table>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span
style='font-size:12.0pt'> <o:p></o:p></span></font>
</div>
</td>
<td style='padding:0in 0in 0in 0in'><!-- Right margin -->
<p class=MsoNormal><font size=3 face="Times New Roman"><span
style='font-size:12.0pt'><o:p> </o:p></span></font>
</td>
</tr>
<!-- Disclaimer -->
<tr>
<td colspan=3 style='padding:0in 0in 0in 0in'>
<p class=MsoNormal><font size=3 face="Times New Roman"><span
style='font-size:12.0pt'><o:p> </o:p></span></font>
<div>
<p class=MsoNormal style='margin-bottom:12.0pt'><font size=1 color=gray
face=Verdana><span style='font-size:7.0pt;font-family:Verdana;color:gray'>In2
Thames House
Mere Park
Dedmere Road
Marlow
Bucks
SL7 1PB
Tel 01628 899700
Fax 01628 899701
e: <a href="mailto:sales@in2.co.uk">sales@in2.co.uk</a>
i: <a href="http://www.in2.co.uk/">www.in2.co.uk</a>
</span></font><font size=1 color=silver face=Verdana><span style='font-size:
7.0pt;font-family:Verdana;color:silver'>This message (and any associated
files) is intended only for the use of discuss@jquery.com and may contain
information that is confidential, subject to copyright or constitutes a trade
secret. If you are not discuss@jquery.com you are hereby notified that any
dissemination, copying or distribution of this message, or files associated
with this message, is strictly prohibited. If you have received this message
in error, please notify us immediately by replying to the message and
deleting it from your computer. Messages sent to and from us may be
monitored. Any views or opinions presented are solely those of the author
Luc.Pestille@in2.co.uk and do not necessarily represent those of the company.
</span></font><font size=1 color=gray face=Verdana><span style='font-size:
7.0pt;font-family:Verdana;color:gray'><o:p></o:p></span></font>
</div>
</td>
</tr>
</table>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'><o:p> </o:p></span></font>
</div>
</div>
</body>
</html>
_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/