Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1845
Select item by value
posted

Has anyone had to set the selected item by value?  There's an "itemByValue" method, but it returns a Jquery object, no index.  The only method that I see for setting the current item, "selectedIndex", only accepts an index as an argument.

I could probably use Jquery to find the index by finding the corresponding value in the DOM, but I don't want to if there's a more elegant way.

Parents
No Data
Reply
  • 2735
    Verified Answer
    posted

    Hi JoshNoe,

    The method itemByValue return object with properties - element, index, text and value. So, you can accomplish your task with this snippet:

    HTML Code:

    ...

     

    <select id="comboColors">

                                    <option value="blackVal">Black</option>

                                    <option value="blueVal">Blue</option>

                                    <option value="brownVal">Brown</option>

                                    <option value="greenVal">Green</option>

                                    <option value="orangeVal">Orange</option>

                                    <option value="purpleVal">Purple</option>

                                    <option value="redVal">Red</option>

                                    <option value="whiteVal">White</option>

                                    <option value="yellowVal">Yellow</option>

                                </select>

    ...

    JavaScript Code:

    ...

     

     

    var item = $("#comboColors").igCombo("itemByValue", "orangeVal");

    $("# comboColors").igCombo("selectedIndex", item.index);

    ...

    Regards,

    Stanimir Todorov

Children
No Data