jQWidgets Forums

jQuery UI Widgets Forums Lists DropDownList how to programmatically set the selected item in DropDownList

This topic contains 3 replies, has 3 voices, and was last updated by  Peter Stoev 11 years, 4 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author

  • ryan paul
    Participant

    How to set the selected item of the DropDownList?

    If for example i have a 5 item dropdownlist
    Hello1
    Hello2
    Hello3
    Hello4
    Hello5

    If i want to select ‘Hello3’ is this going to work,
    $(‘#DropDownList1’).jqxDropDownList(‘selectItem’, ‘Hello3’);
    this approach is not going to work.

    I do not want to select by using the index of the dropdownlist because i will get the value from a grid.
    And what is the datatype of the parameter being passed in the dropdownlist selectItem method?


    Peter Stoev
    Keymaster

    Hi ryan paul,

    Actually, that will work in jQWidgets 2.8.

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" type="text/css" />
    <script type="text/javascript" src="../../scripts/gettheme.js"></script>
    <script type="text/javascript" src="../../scripts/jquery-1.8.3.min.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxcore.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxbuttons.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxscrollbar.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxlistbox.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxdropdownlist.js"></script>
    </head>
    <body>
    <div id='content'>
    <script type="text/javascript">
    $(document).ready(function () {
    var source = [
    "Hello 1",
    "Hello 2",
    "Hello 3",
    "Hello 4",
    "Hello 5"
    ];
    // Create a jqxDropDownList
    $("#jqxWidget").jqxDropDownList({ source: source, width: '200', height: '25'});
    $("#jqxWidget").jqxDropDownList('selectItem', 'Hello 3');
    });
    </script>
    <div id='jqxWidget'>
    </div>
    </div>
    </body>
    </html>

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com


    bhanu.vaddavalli
    Participant

    the above approach is also not worked for me


    Peter Stoev
    Keymaster

    Hi bhanu.vaddavalli,

    It works with jQWidgets 2.8+ versions. The result is that the selected item is “Hello 3”.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.