Thanks for the reply and code... As far as the "_" vs "-", I've been trying to standardize on using "_" for input names (which is necessary for the database) and "-" for the id's and classes, but now, working with jQuery like this, it is creating a problem.
Rick > -----Original Message----- > From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] On > Behalf Of MorningZ > Sent: Monday, December 22, 2008 1:44 PM > To: jQuery (English) > Subject: [jQuery] Re: How can I generalize this code for all values? > > > Just some advice: why mix "-" and "_" all up? it makes it easier if > they were the same > > for instance > > <input type="text" id="street_number" /> > <img id="street_number_error" src="error.png" /> > > <input type="text" id="street_name" /> > <img id="street_name_error" src="error.png" /> > > > $("input[id^='street_']").each(function() { > var val = $.trim(this.value); > if (val == "") { > $("#" + this.id + "_error").fadeIn(500); > } > else { > $("#" + this.id + "_error").fadeOut(500); > } > $("#submit").attr("disabled", (val == "") ? "disabled" : ""); > }); > > > > > On Dec 22, 1:10 pm, "Rick Faircloth" <r...@whitestonemedia.com> wrote: > > Don't know if that's the best phrasing for the subject, > > but what I'm trying to do is develop some code that > > will work for all for inputs of type 'text', instead > > of hard-coding the id values. > > > > The original code is this: > > > > $('input#street_number').blur(function() { > > > > if (this.value.length == 0) > > { $('#street-number-required-error').fadeIn(500); > > $('#submit').attr('disabled', 'disabled') } > > if (this.value.length > 0) > > { $('#street-number-required-error').fadeOut(500); > > $('#submit').attr('disabled', '') }; > > > > }); > > > > $('input#street_name').blur(function() { > > > > if (this.value.length == 0) > > { $('#street-name-required-error').fadeIn(500); > > $('#submit').attr('disabled', 'disabled') } > > if (this.value.length > 0) > > { $('#street-name-required-error').fadeOut(500); > > $('#submit').attr('disabled', '') }; > > > > }); > > > > Here's my coding attempt: (no errors in firebug, but not response > > from the DOM)... > > > > $(document).ready(function() { > > $("inp...@type='text']").each(function(i) { > > $(this).blur(function() { > > if (this.value.length == 0) > > { $(this.id.replace(/_/g, '-')+'-error').fadeIn(500); > > $('#submit').attr('disabled', 'disabled') } > > else > > { $(this.id.replace(/_/g, '-')+'-error').fadeOut(500); > > $('#submit').attr('disabled', '') } > > }); > > }); > > > > }); > > > > Anyone care to offer guidance to get this working? > > > > Thanks, > > > > Rick