Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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)?
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
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?
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?
Don't know if this will help you, but see post here... http://community.qlik.com/message/142080#142080
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>