jQuery UI Widgets Forums Lists ComboBox Combobox test if selected item is null or undefined

This topic contains 1 reply, has 2 voices, and was last updated by  Dimitar 10 years, 11 months ago.

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

  • Gopre400
    Participant

    Hi I am using the combobox widget and was wondering if there is a way to test if “$(‘#cmbVehicleNbr’).jqxComboBox(‘getSelectedItem’)” is null or undefined? To get the value of the combobox I was using $(‘#cmbVehicleNbr’).val() however if the user types or deletes characters in the combobox that value will used instead of the selected item. To remedy this I tried using getselecteditem however if I type or delete charachters I get this error “Error: Unable to get value of the property ‘value’: object is null or undefined” with this code:

    var item = $(‘#cmbVehicleNbr’).jqxComboBox(‘getSelectedItem’);
    alert(item.value);

    Is there a way to test if selected item is null or undefined? Or a better way to ensure something has been selected?

    Thanks
    John


    Dimitar
    Participant

    Hello John,

    Please try the following approach:

    $("#getSelectedItem").click(function () {
        var item = $("#cmbVehicleNbr").jqxComboBox('getSelectedItem');
        if (item) {
            alert(item.value);
        } else {
            alert("No item has been selected.");
        };
    });

    Best Regards,
    Dimitar

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

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

You must be logged in to reply to this topic.