actually it might work var obj = $("#mdiv select");
for(var i=0; i < obj.length; i++) { obj.eq(i) .... } // the above method will get alll <select> tags within a <div> tag and loop then if you want to loop the options within them you can either make obj to be $("#mydiv select option"); or you can run a loop within a loop like so var obj = $("#mdiv select"); for(var i=0; i < obj.length; i++) { var objtwo = obj.eq(i); var ops= ("option", objtwo); for(var j = 0; j < ops.length; i++) { if(ops.eq(i) == 0) { break; } else { // do stuff } } } this should be according to your new idea. but will this really work for you ? too much looping does use more memory. the simple click function i mentioned would use less memory since i set $("select") it would get the click of any select you do click. and it returns the value of the selected item. if you have a specific goal you want to achieve it would allow us to help you better if we knew. <script> $(function() { $("select").click(function() { var value = $(this).val(); if(val != 0) { // do what you need to do } else { alert("you have not selected an option"); } }); }); </script> On Mon, May 11, 2009 at 8:47 PM, Loony2nz <loony...@gmail.com> wrote: > > @Mike: Yeah that won't work. Most of the values aren't unique. > > > > On May 11, 11:43 am, Mean Mike <mcgra...@gmail.com> wrote: > > wouldn't it make more sense to just have one drop down menu with all > > school choices in it ? as long as all the schools differ in value I > > pretty sure that would make your life easier > > > > On May 11, 1:41 pm, Loony2nz <loony...@gmail.com> wrote: > > > > > I had a better thought. > > > > > How do I get the count of <select> options within a div? > > > I can then loop thru the select options and see if any of them are > > > value "0". > > > > > Is this possible? > > > > > On May 11, 10:09 am, waseem sabjee <waseemsab...@gmail.com> wrote: > > > > > > i suggest for this line > > > > <option value="">Select something</option> > > > > you assign the value of "0" > > > > > > in order to retrieve this value use the following js > > > > <script> > > > > $(function() { > > > > > > $("select").click(function() { > > > > > > var value = $(this).val(); > > > > if(val != 0) { > > > > // do what you need to do} else { > > > > > > alert("you have not selected an option"); > > > > > > } > > > > }); > > > > }); > > > > > > </script> > > > > > > On Mon, May 11, 2009 at 6:55 PM, Loony2nz <loony...@gmail.com> > wrote: > > > > > > > I need some help with jquery's syntax for how to pop an error > message > > > > > when a select field is blank. > > > > > > > There's a form that uses the same css class for all of it's form > > > > > fields. However, I would like to check to see if at least one > section > > > > > of the form is not "blank". > > > > > > > Here's my code: > > > > > > > <div id="schoolchoices"> > > > > > <select name="9378_choice" class="schoolDropList"> > > > > > <option value="">Select something</option> > > > > > <option value="10">10</option> > > > > > <option value="20">20</option> > > > > > <option value="30">30</option> > > > > > <option value="40">40</option> > > > > > <option value="50">50</option> > > > > > </select> > > > > > <br /><br /> > > > > > <select name="3483_choice" class="schoolDropList"> > > > > > <option value="">Select something</option> > > > > > <option value="10">10</option> > > > > > <option value="20">20</option> > > > > > <option value="30">30</option> > > > > > <option value="40">40</option> > > > > > <option value="50">50</option> > > > > > </select> > > > > > <br /><br /> > > > > > <select name="2384_choice" class="schoolDropList"> > > > > > <option value="">Select something</option> > > > > > <option value="10">10</option> > > > > > <option value="20">20</option> > > > > > <option value="30">30</option> > > > > > <option value="40">40</option> > > > > > <option value="50">50</option> > > > > > </select> > > > > > </div> > > > > > > > I need to check to see if at least one of the above is not "blank". > > > > > Here's the catch. The list of school choices is variable. It can > be > > > > > 1 school choice, it could be 4 school choices. But it's > dynamically > > > > > generated and I need to create a jquery js function that will > validate > > > > > at least 1 of the x school choices are chosen. The value of the > > > > > select statement is dynamically generated to use the school's > database > > > > > ID. > > > > > > > There are other form elements to this sample code, but I only need > > > > > this section of the form validated. > > > > > > > Thoughts on how to progress? > > > > > > > Thanks! >