jQWidgets Forums

jQuery UI Widgets Forums Lists DropDownList how to get old seleted item on change function

This topic contains 2 replies, has 2 voices, and was last updated by  Nadezhda 10 years, 8 months ago.

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

  • anandbabu
    Participant

    Hi ,
    I am using jqxdropdownlist,in change function i have to set previous selected item to drop down list when validation fails for the list.
    like in JQXGrid we can get event.args.oldValue like wise whether we can get old selected item in dropdownlist.


    anandbabu
    Participant

    hi team,
    Please reply for the above post….


    Nadezhda
    Participant

    Hello anandbabu,

    Please, find below an example which shows how to get old selected item on change event:

    <!DOCTYPE html>
    <html lang="en">
    <head>    
        <title></title>
        <link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" type="text/css" />
        <script type="text/javascript" src="../../scripts/jquery-1.11.1.min.js"></script>
        <script type="text/javascript" src="../../scripts/demos.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/jqxpanel.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxlistbox.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxdropdownlist.js"></script>
        <script type="text/javascript">
            $(document).ready(function () {
                var source = [
                    "Affogato",
                    "Americano",
                    "Bicerin",
                    "Breve",
                    "Liqueur coffee"
                ];
    
                var oldvalue = 0;
                $("#jqxDropDownList").jqxDropDownList({ source: source, selectedIndex: oldvalue, width: '200px', height: '25px' });
                $('#Events').jqxPanel({ height: '250px', width: '200px' });
                $('#Events').css('border', 'none');
                // subscribe to 'unselect' and 'select' events.
                $('#jqxDropDownList').on('change', function (event) {
                    var args = event.args;
                    if (args) {
                        // index represents the item's index.                          
                        var index = args.index;
                        $('#Events').jqxPanel('prepend', '<div style="margin-top: 5px;">Previous: ' + oldvalue + '</div>');
                        oldvalue = index;
                        $('#Events').jqxPanel('prepend', '<div style="margin-top: 5px;">Current: ' + oldvalue + '</div>');
                        var item = args.item;
                        // get item's label and value.
                        var label = item.label;
                        var value = item.value;
                    }
    
                });
    
            });
        </script>
    </head>
    <body>
        <div id='content'>
            <div style='float: left; width: 500px;' id='jqxWidget'>
                <div style='float: left; margin-top: 10px;' id='jqxDropDownList'>
                </div>
                <div style='margin-left: 20px; margin-top: 10px; float: left;'>
                    <div>
                        <span>Events:</span>
                        <div id='Events'>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </body>
    </html>

    Best Regards,
    Nadezhda

    jQWidgets team
    http://www.jqwidgets.com/

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

You must be logged in to reply to this topic.