Open In App

jQWidgets jqxListBox getSelectedItem() Method

Last Updated : 05 Oct, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

jQWidgets is a JavaScript framework for making web-based applications for PC and mobile devices. It is a very powerful, optimized, platform-independent, and widely supported framework. The jqxListBox is used to illustrate a jQuery ListBox widget which comprises a list of electable elements.

The getSelectedItem() method is used to return the selected item from the stated list. Moreover, the returned value is of type object or else null, in case no selected item is selected. It has no parameter and it returns an object.

The returned value is an object with the following fields:

  • label
  • value
  • disabled
  • checked
  • hasThreeStates
  • html
  • index
  • group

Syntax:

var item = $("#jqxListBox").jqxListBox('getSelectedItem');  

 

Linked Files: Download jQWidgets from the link. In the HTML file, locate the script files in the downloaded folder.

<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=”jqwidgets/jqx-all.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>

Example: The below example illustrates the jqxListBox getSelectedItem() method in jQWidgets.

HTML




<!DOCTYPE html>
<html lang="en">
    <head>
        <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="jqwidgets/jqx-all.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>
    </head>
  
    <body>
        <center>
            <h1 style="color: green;">
                GeeksforGeeks
            </h1>
  
            <h3>
                jQWidgets jqxListBox getSelectedItem() Method
            </h3>
  
            <div id="jqxLB"></div>
            <br />
            <input type="button" id="jqxBtn" 
                style="padding: 5px 20px;" 
                value="get the selected item" />
        </center>
        
        <script type="text/javascript">
            $(document).ready(function () {
                var data = [
                  "Computer Science", 
                  "C Programming",
                  "C++ Programming"];
  
                $("#jqxLB").jqxListBox({
                    source: data,
                    width: "200px",
                    height: "80px",
                    selectedIndex: 2
                });
                  
                $("#jqxBtn").on("click", function () {
                     var itm = $("#jqxLB").jqxListBox('getSelectedItem');
                     console.log("Selected item is: " + itm.label);
                });
            });
        </script>
    </body>
</html>


Output:

getSelectedItem method

Reference: https://www.jqwidgets.com/jquery-widgets-documentation/documentation/jqxlistbox/jquery-listbox-api.htm?search=



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads