The classes should be separated by a ',' (Comma). Please check out the documentation on Selectors, having spaces it looks for the second class within the first class sub-children. That's not what you desire.
Try the following code : $(".numAdultsField, .numChildrenField").blur(function() { var id = $(this).attr("id"); var eltPrefix = id.substring(0, id.toLowerCase().indexOf ("num")).replace(":", "\\:"); var numAdultsElt = $('#' + eltPrefix + 'NumAdults'); var numChildrenElt = $('#' + eltPrefix + 'NumChildren'); var total = 0; if (parseInt(jQuery.trim(numAdultsElt.val())) > 0) { total += parseInt(jQuery.trim(numAdultsElt.val())); } // if if (parseInt(jQuery.trim(numChildrenElt.val())) > 0) { total += parseInt(jQuery.trim(numChildrenElt.val())); } // if $('#' + eltPrefix + 'TotalInParty').val(total); }); Thanks & Regards, Dhruva Sagar. On Wed, Nov 18, 2009 at 9:29 PM, laredotorn...@zipmail.com < laredotorn...@zipmail.com> wrote: > Hi, > > I have to apply an onblur function to elements of type > "numAdultsField" or "numChildrenField". How do I do that? This isn't > working ... > > $(".numAdultsField .numChildrenField").blur(function() { > var id = $(this).attr("id"); > var eltPrefix = id.substring(0, id.toLowerCase().indexOf > ("num")).replace(":", "\\:"); > var numAdultsElt = $('#' + eltPrefix + 'NumAdults'); > var numChildrenElt = $('#' + eltPrefix + 'NumChildren'); > var total = 0; > if (parseInt(jQuery.trim(numAdultsElt.val())) > 0) { > total += parseInt(jQuery.trim(numAdultsElt.val())); > } // if > if (parseInt(jQuery.trim(numChildrenElt.val())) > 0) { > total += > parseInt(jQuery.trim(numChildrenElt.val())); > } // if > $('#' + eltPrefix + 'TotalInParty').val(total); > }); > > - Dave >