You're making it much more complex than it needs to be, besides the fact that your posted code doesn't make much sense as that "return qty" isn't returning the value anywhere
$("#parameters").change(function () { var values = $(this).val() || []; $("#qty").val(values.length; }) On Nov 25, 8:49 am, Sai Krishna <[EMAIL PROTECTED]> wrote: > Hi, > > I'm a newbie to Jquery. I wrote the following function for multi > select > var quantity =0; > $("#parameters").click(function () { > var qty = 0; > $("#parameters option:selected").each(function () { > qty = qty+1; > }); > $("#qty").val(qty); > return qty; > > }) > > and the multi select list box with the following code > > <select name='parameters' id='parameters' multiple='multiple' > > <option value='2' >value2</option> > <option value='1' >value1</option> > <option value='3' >value3</option> > </select> > > This updates a hidden form variable quantity. Now I changed to name > "parameters" to "parameters[]". > > The function seems to be not working. Probably I need to length I > tried $("#parameters length()"). This seems to be not working. Can > somebody help me?