We help IT Professionals succeed at work.

Loop dropdown in Jquery

sivaman
sivaman asked
on
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
Comment
Watch Question

Commented:
$('#ddlSalesRep option[value="' + UserId + '"]').attr('selected', 'selected');

Author

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
Commented:
To hide
$('#ddlSalesRep').hide();

Open in new window


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

Open in new window

Author

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