Click here to Skip to main content
15,890,336 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here is my js & css File.
HTML
<script src="https://ajax.googleapis.com/ajax/libs/prototype/1.7.0.0/prototype.js" type="text/javascript"></script>
    <script src="chosen.proto.js" type="text/javascript"></script>
    <script src="docsupport/prism.js" type="text/javascript" charset="utf-8"></script>
    <script type="text/javascript">
        document.observe('dom:loaded', function (evt) {
            var config = {
                '.chosen-select': {},
                '.chosen-select-deselect': { allow_single_deselect: true },
                '.chosen-select-no-single': { disable_search_threshold: 10 },
                '.chosen-select-no-results': { no_results_text: "Oops, nothing found!" },
                '.chosen-select-width': { width: "95%" }
            }
            var results = [];
            for (var selector in config) {
                var elements = $$(selector);
                for (var i = 0; i < elements.length; i++) {
                    results.push(new Chosen(elements[i], config[selector]));
                }
            }
            return results;
            
        });
  </script>


Here is my design div
HTML
<div class="side-by-side clearfix">
    <div>
        Single Select with Groups
    </div>
    <div>
        <asp:DropDownList ID="ddlchk1" runat="server" data-placeholder="Your Favorite Football Team" style="width: 350px;" multiple class="chosen-select">
    </div>
</div>

This code working perfectly and display multiple selected dropdown value, but I want save the selected valu to my sql server database.

What I have tried:

Here is my js file code. I want populate the selected values but its not working perfectly.
JavaScript
$(document).ready(function () {
    alert("dsd");
    $(document).ready(function () {
        $("#ddlchk1").chosen();
        $("#btnSubmit").click(function () {
            console.log($("#ddlchk1").val());
            alert(console.log($("#ddlchk1").val()));
        });
    });
})
Posted
Updated 14-Mar-20 22:43pm
v2
Comments
George Jonsson 9-May-16 21:21pm    
Elaborate on what you expect to happen and what is actually happening.
"not working perfectly" is not a very good problem description.
bigyan sahoo 9-May-16 22:32pm    
how to save the selected list item values of dropdown in database. and also when I add <script src="js/jquery-1.5.1.min.js"></script> this js file for show the selected data in button click(Input button) the whole design does not working properly...
George Jonsson 9-May-16 22:42pm    
And what is the problem?
I cannot see any call to a database in your code, I suppose you are stuck getting the list of selected values from the dropdown list. Is that about right?
bigyan sahoo 9-May-16 22:52pm    
after selection when I click on my button, I want to display the selected values in an alert(). so after that I can save them by assign them to a hidden filed and send to my code , but I am unable to fetch my selected items.
bigyan sahoo 10-May-16 0:29am    
This is the link that I had follow for my project requirement.
http://harvesthq.github.io/chosen/

See at the (Multiple Select with Groups) on the third div. I have already disply the data in my Dropdownlist and select them as it works. But unable to fetch and save them.

1 solution

Have a look here, it might be what you are looking for.

Get selected value of a dropdown&#39;s item using jQuery - Stack Overflow[^]

Try this code
JavaScript
function get_selections(){
    alert($('#ddlchk1 :selected').text());
}


It will give you a list of names, but without a separator.
 
Share this answer
 
v2
Comments
bigyan sahoo 10-May-16 1:07am    
This is the link that I had follow for my project requirement.
http://harvesthq.github.io/chosen/

See at the (Multiple Select with Groups) on the third div. I have already disply the data in my Dropdownlist and select them as it works. But unable to fetch and save them.
George Jonsson 10-May-16 5:30am    
See my updated solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900