Loop dropdown in Jquery


I have a client side dropdown populated with value and text.

                                     $("#ddlSalesRep").append($("<option value=" + SalesRep.UserId + ">"  + SalesRep.LastName +", "+ SalesRep.FirstName +" - " + SalesRep.CustomerId + " </option>"))

My requirement is I need to loop through the dropdown, find a specific value and set that as the selected.
In my case  SalesRep.UserId is the value field. I want to find a specific sales rep with a user id and set that as the selected.

I would appreciate if anyone could help. Also please send me a link which I can refer for Jquery.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

$('#ddlSalesRep option[value="' + UserId + '"]').attr('selected', 'selected');
sivamanAuthor Commented:
Cool. This works..Could you also let me know how to hide a client side dropdown in Jquery. My dropdown is inside a <td>.

To hide

Open in new window

To show

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sivamanAuthor Commented:

Could you please let me know how to debug asynchronous calls in jquery.

In the below attached code, I want to debug the success function(response) line by line. If I keep a break point now, its just a single break point .

How do I debug this call line by line? Any help would be much appreciated.


$("#ddlSalesRep").change(function () 
             var ddl=$("#ddlCustomer").html(' ');
             ddl.append($("<option value=''> -- Select Customer --</option>"))
             var SalesRepId = $("#ddlSalesRep").val();
                  url         :'/irj/servlet/prt/portal/prtroot/com.medline.medpack.CustomerBenefitStatement.CustomerBenefitStatement?ActionName=GetCustomerList&SalesRepId='+SalesRepId,
                  type        : "POST",
                  dataType    : "text",
                  contentType : "text/plain",
                  success     : function (response) { 
                                  var data = jQuery.parseJSON(response);                                                                     
                                    $.each(data.CustomerList, function (i, CustomerList) 
                                       //ddl.append($("<option value="+ CustomerList.CustomerId + ">" + CustomerList.CustomerName + " " + "["+ CustomerList.CustomerId + "]" +" "+ "[PK:" + CustomerList.PackCount + "]"+" "+"[QTE:" + CustomerList.QuoteCount + "]" + "</option>"))
                                        ddl.append($("<option value="+ CustomerList.CustomerId + ">" + CustomerList.CustomerDropDownDisplayAllData + "</option>"))
                   error       : function(msg, text) 
                                  $("#errorMsgBoard").append('<label><br /><b>There is an issue while performing requested operation</b> <br /><br /></label>');
                                  $("#spinnerimg").attr("visibility", "visible");


Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.