> I have the following:
>
>   if (subject == '---') {
>     if(!$('label[for="Subject",class="Error"]').length) {
>       $('#Subject').parent().after('<label for="Subject"
> generated="true" class="Error">Required field</label>');
>     }
>   }
>
> I need to check if a label with for="Subject" and class="Error"
> exists:
>
> if(!$('label[for="Subject",class="Error"]').length)

I'm not up enough on my CSS selector syntax to know if multi-attribute
selectors like that are valid, but you should be able to simplify
somewhat like:

$('label.Error[for="Subject"]')

to locate the element(s) you're looking for.

Have you thought about how forms will be validated if the client has
JavaScript disabled?  Will the server generate similar HTML when it
does validation?  If so, are you duplicating effort client- and server-
side that could be left just to the server?

It might also be worth checking out:

http://jquery.com/blog/2007/07/04/about-client-side-form-validation-and-frameworks/

for some discussion on the subject of client-side form validation.

HTH!

Reply via email to