Arun
Arun

Reputation: 3731

Change selected value of DDSlick dropdown using JavaScript

In my website, I am using the DDSlick plugin for styling my select dropdown. It is nice. But I can't change the selected value using javascript.

For example, if the current selected value is "INDIA", then I want to change "INDIA" to "USA" by using javascript, without refreshing the page. Is there any way to do this?

Thanks in advance.

Upvotes: 1

Views: 3374

Answers (1)

Devima
Devima

Reputation: 1566

If you want force a specific selected items on click on buttons you culd use this code.

<!DOCTYPE HTML>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript" src="jquery.ddslick.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    $('#dropdown').ddslick({
        width: 300,
        selectText: "Select an item",
        onSelected: function (data) {
            console.log(data)
        }
    });

    $('#button').on('click', function () {
           $('#dropdown').ddslick('select', {index: 2 });
    });
})
</script>
</head>
<body>
<select id="dropdown">
    <option>select</option>
    <option id="a" value="">INDIA</option>
    <option id="b" value="">USA</option>
    <option id="c" value="">AFRICA</option>
</select>
<input name="" type="button" value="change" id="button">
</body>
</html>

with similar code you can create a button to browse through all the options in the list
fiddle
If this solution does not suit your needs, i apologize for making you lose time.

Upvotes: 2

Related Questions