Thanks for the pointer :)! -----Original Message----- From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] On Behalf Of Ricardo Sent: 28 June 2009 20:27 To: jQuery (English) Subject: [jQuery] Re: Help with some jquery basics
You're trying to set the 'opid' property of opid[0] when it doesn't exist. You should either create an object in that position first: opid[i] = {}; opid[i]['opid'] = $(this).attr("id").substr(9); Or just save it directly to the index (like a simple array): opid[i] = $(this).attr("id").substr(9); A few recommendations: use the array literal instead of new Array(): var opid = []; Try to rely less on slicing your ID to match other elements, use classes and tagnames instead: $('#'+userid').each(function(){ $(this).find(':checkbox')... $(this).find('input.pa')... }); That way your code will be less prone to errors. On Jun 26, 4:11 pm, Lee <leejohnhan...@googlemail.com> wrote: > Can someone help me to get opid to be populated. The selectors all > work correctly, and the code cycles the correct elements (tested this > with an alert). Problem is I need to get the values I cycle in the > each statement out and into the wrapping click function. > > Anyhelp would be appreciated. At the moment I get an opid[i] undefined > error.... Thanks for any help you can offer > > var opid = new Array(); > > $("a.btn.submit").click(function(){ > // alert($(this).attr("id").substr(7)); > var userid = $(this).attr("id").substr(4); > > $("#"+userid+" input:disabled").each(function(i){ > // var opid = new Array(); > if($("#chk_"+$(this).attr("id").substr(9)).is(":checked")) > { > > if ($("#pa_"+$(this).attr("id").substr(9)).val() == '') > { > //display error, > alert("If you have selected to submit a PO you must give it a > weighting"); > var error = 1; > } > else > { > alert($(this).attr("id").substr(9)+" "+$(this).val()+" "+$("#pa_"+ > $(this).attr("id").substr(9)).val()) > opid[i]['opid'] = $(this).attr("id").substr(9); > alert(opid[i]['opid']); > } > } > else > { > // alert("not selected"); > } > > i++ > }); > });