Tuesday, September 10, 2019

jQuery: get the selected text as comma separated from select box



$('#<%=ddlCustomer.ClientID %>').change(function (event) {
                event.preventDefault(); 
                  var arr = $(this).val();
                    console.log(arr)
                    console.log(arr.join(", "));
                    $("#<%= hdnCustomerId.ClientID %>").val(arr.join(", "));  // 1,2,3,4,5
                  var option_all = $("select option:selected").map(function () {
                    return $(this).text();
                }).get().join(',');
                console.log(option_all);             
             $("#<%= hdnCustomerName.ClientID %>").val(option_all); // Test1,Test2,Test3,Test4,Test5
                return false;
            });

No comments:

Post a Comment