Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

GetText from TextBox via Javascript API

Hi there,

I'm trying to retreive the Value of an TextBox via the Ajax API...

Refering to the AjaxAPI documentation there is a method called GetText()...

I tried this

var myObj = qva.GetQvObject("TX21");   //it's a TextBox Object

var text = myObj.GetText();

alert("text");

Unfortunately I'm getting an Error, saying that myObj.GetText is not a function.

What am i doing wrong?

any ideas?

help would be much appreciated!

kind regards,

pat

6 Replies
Not applicable
Author

The reason you are getting the error is because QlikView Ajax Public API is not implemented until the GetQvObject() has executed it's onUpdate function.  The onUpdate function is the second parameter that can be used by the GetQvObject function which is where you need to make your call.  You can call the on update function like so...

var text;

var myObj = qva.GetQvObject("TX21", function () {

      text = textObject.QvaPublic.GetText();

      alert("the text value is: " + text;

});

---- Another way to look at it... ----

var text;

function onUpdate() {

      text = textObject.QvaPublic.GetText();

      alert(text); // you should see the text.

}

var myObj = qva.GetQvObject("TX21", onUpdate);

// notice that any references to text immediately after this are null and undefined. This is because the onUpdate callback function has not been executed yet...

alert(textObject.QvaPublic.GetText()); // the value of QvaPublic is "undefefined"

alert(text); // the value of text here is null

Not applicable
Author

many thanks for this!

tduarte
Partner - Creator II
Partner - Creator II

Hi there,

I've used the code above to also return the context of a textbox but it's not working.

I'm getting the following error on the brower degub console: "textObject is not defined"

Any clues?

Thanks,

Telmo

Not applicable
Author

oops...

myObj should be textObject... correction below...

var text;

var textObject = qva.GetQvObject("TX21", function () {

      text = textObject.QvaPublic.GetText();

      alert("the text value is: " + text;

});

tduarte
Partner - Creator II
Partner - Creator II

Yes, that works and it makes sense I must say.

That's why I could not find textObject on the API!

Thanks a lot.

tduarte
Partner - Creator II
Partner - Creator II

Is there a way we can store the text in the variable without doing it within textObject so that we can use it in another function for example?