Hi Luc,
This is a little smaller... yet surely not perfect
$('form#checkout').submit(function() {
var $forename = $('input#rxt_forename');
var forename = $forename.get(0);
if($forename.val() == '' ){
forename.focus();
$forename.addClass("required").siblings("span.error").show();
return false;
}else{
$forename.removeClass("required").siblings("span.error").hide();
}
});
-- Marc
Luc Pestille schrieb:
>
>
> Hi all,
> I've got some simple validation to do (not enough to use one of the
> form plugins), and have this;
>
> // 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();
> }
>
> 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...
>
> Thanks,
>
>
>
>
>
> *Luc Pestille*
> Web Designer
>
> e: [EMAIL PROTECTED]
> t: +44 (0)1628 899 700
> f: +44 (0)1628 899 701
>
>
>
>
> In2
> Thames House
> Mere Park
> Dedmere Road
> Marlow
> Bucks
> SL7 1PB
>
> Tel 01628 899700
> Fax 01628 899701
> e: [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
> i: www.in2.co.uk <http://www.in2.co.uk/>
>
> This message (and any associated files) is intended only for the use
> of [email protected] and may contain information that is
> confidential, subject to copyright or constitutes a trade secret. If
> you are not [email protected] 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 [EMAIL PROTECTED] and do not
> necessarily represent those of the company.
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> jQuery mailing list
> [email protected]
> http://jquery.com/discuss/
>
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/