5 Replies Latest reply: Aug 18, 2011 12:10 PM by JuliusHutzler RSS

    Accessing Selected Items in a Listbox using Javascript

      I am trying to access a listbox control in my QVW from my ASPX page and find out if it has any items selected. In VBScript you might see code similar to :


      set LB=ActiveDocument.GetSheetObject("LB76")

      set boxfield = LB.GetField

      if boxfield.GetFieldFlags.HasSelection then

        FS = 1



      Does anyone know the equivalent code in Javascript to get find out if a listbox control has a selected item(s)?


        • Accessing Selected Items in a Listbox using Javascript
          Dan English

          Hi bkirkman,


          You can get a reference to a listbox using our AJAX API like this:


               function init() {

                     var myListBoxObject = this.GetQvObject("LB02", function(){});

                     alert(myListBoxObject.Name + " " + myListBoxObject.mode);





          That example code is as if you were in an extension object. In v11 you will be able to do this sort of thing from a document extension (see the beta forum for more details on document extensions).


          Once you have the reference to the listbox object you can use the GetSelected() method.



            • Re: Accessing Selected Items in a Listbox using Javascript


              Ok, this is what I've tried so far and any comments/hints are welcome.

              The goal is to get the selected items from a QV Workbench Listbox object in my .net web application. I need to do some validation on a button click that involves the Listbox.


              So here is my javascript function that gets called on the button click:


              function OpenmodalCheckout() {







              var selectedallrs = qva.GetQvObject("LB56", GetSelectedRateSheets, this);




                   var selectedCount = selectedallrs.length;


              if(selectedCount >0)


                .. do stuff ..


              return false;



              And the other function on the getqvobject call





              GetSelected() {

              var selrs = this.Data.GetEnabled();

              return selrs;




              What happens though is that the GetSelected method gets called AFTER the OpenModalCheckout gets called so my selectedCount is undefined. Why is that?



                • Re: Accessing Selected Items in a Listbox using Javascript

                  I got this to work but not as I expected.


                  I had to add this code into my Init function so that I get the listbox I want and then get the selected items from the object then store them in a ASP.NET hiddenfield so I can access them during the web page's lifecycle. Trying to just access the control in a javascript method on say a button click always returned a null object.


                  This seems to be a hack way to work with these objects so can anyone tell me how to access the QlikView object on say a button click event in my javascript instead of having to always do this in my Init function?