Loop dropdown in Jquery

Hi,

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.

Thanks
Siva
sivamanAsked:
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.

StingRaYCommented:
$('#ddlSalesRep option[value="' + UserId + '"]').attr('selected', 'selected');
0
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>.

Thanks
Siva
0
StingRaYCommented:
To hide
$('#ddlSalesRep').hide();

Open in new window


To show
$('#ddlSalesRep').show();

Open in new window

0

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:
Hi,

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.

Thanks
Siva


$("#ddlSalesRep").change(function () 
 {
             var ddl=$("#ddlCustomer").html(' ');
             ddl.append($("<option value=''> -- Select Customer --</option>"))
             var SalesRepId = $("#ddlSalesRep").val();
             alert(SalesRepId);             
             $.ajax({                 
                  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);                                                                     
                                    ddl.attr('disabled',false);
                                    $.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").fadeOut();
                                  $("#spinnerimg").attr("visibility", "visible");
                                  $("#divBody").css('cursor','auto');

                                }
              });
});

Open in new window

0
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
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.