Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

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)?

5 Replies
Not applicable
Author

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);

     }

     Qva.BodyOnLoadFunctionNames.push('init');

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.

-Dan

Not applicable
Author

Dan,

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);

if(selectedallrs)

{

     var selectedCount = selectedallrs.length;

}

if(selectedCount >0)

{

  .. do stuff ..

}

return false;

}

And the other function on the getqvobject call

function

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?

Not applicable
Author

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?

Not applicable
Author

Don't know if this will help you, but see post here... http://community.qlik.com/message/142080#142080

Not applicable
Author

var listboxes = {};  // will be used as a collection of list boxes.

function Init() {

     listboxes["LB1"] = qva.GetQvObject("LB1", function () {

                             

     });

     listboxes["LB2"] = qva.GetQvObject("LB2", function () {

                             

     });

}

Qva.BodyOnLoadFunctionNames.push("Init");

...

function dosomething(listboxId) {

     var selectedData = listboxes[listboxId].QvaPublic.Data.GetSelected();

     ... do something...

}

...

<div id="bla1" onclick="dosomething('LB1');">get selected from lb1</div>

<div id="bla2" onclick="dosomething('LB2');">get selected from lb2</div>