Jump to content

Recommended Posts

Posted

Hi,

I'm having troubles trying to pass a value from a label to javascript.

I've already searched a lot of topics about it here, but none of them worked for me.

I tried to replicate this example: https://support.tibco.com/s/article/Tibco-KnowledgeArticle-Article-45505_ga=2.130727247.1933645704.1560176404-1510580711.1547722993

But it didn't work. I've attached in this post my attempts.

My Spotfire version is 7.14

HTML Code:

Count of "JBF A" with label:

 

 

 

Count of "JBF A" with Calculated Value: 

 

 

Count of "JBF A" manual: 

6Javascript Code:

 

 

var labelVal = $("labelJBF").text();

alert('Label >> ' + labelVal);

 

var calcV = $("calcVV").text();

alert('Calculated Value >> ' + calcV);

 

var manualVal = $("manualV").text();

alert('Manual >> ' + manualVal);

 

var calcID = $("2e9830d4a91b405ba7628907457683f8").text();

alert('Directed ID >> ' + calcID);

 

As you can observe, i tried to get the value with javascript from Label, from calculated value, manually inputted, direct from spotfire ID.. But in all of them, alerts appear blank, like these:

Posted

I found a solution.. Instead of Label, I created a Inputfield.

 

 

 

var teste = document.getElementById("testeInput").childNodes[1].value;

alert(teste);

It works perfectly.. I don't know why whit labels it doesn't work..

Posted

Hi there,

 

Two small changes to your original example, and it should work perfectly. You need to add # to the start of each of your selectors i.e the $("name") should be $("#name"). This tells Javascript to look for a tag with that id.

 

var labelVal = $("#labelJBF").text();
alert('Label >> ' + labelVal);

var calcV = $("#calcVV").text();
alert('Calculated Value >> ' + calcV);

var manualVal = $("#manualV").text();
alert('Manual >> ' + manualVal);

var calcID = $("#2e9830d4a91b405ba7628907457683f8").text();
alert('Directed ID >> ' + calcID);

 

You then need to add your javascript code as a Javascript code snippet using the 'Insert Javascript' on the top right of the icon menu when editing the HTML of your text area. Then give you script a name and paste in the code (without the script tags).

 

Its always better to use the insert javascript option over adding javascript directly into the HTML where possible.

 

The reason your second method works is becuase it is using a traditional javascript element selector rather than a JQuery selector (which requires # or .'s to identify tags). However, the original method can be used with more things such as labels etc.

 

Hope this helps

 

Colin

Posted

Colin, thank you very much! I was racking my brains, but it was only one character lol

Can i you help with this:

I've added the script in "insert js" like you suggested, but I made a mistake and instead of editing current script, i was clicking in "insert js", and the script had replicated many times. So i removed the script, but now appears a lot of: "The script has been removed." How I clear this See the image in attatch to better understand

Posted
I've seen this happen before. If you click on each one and then press delete it should remove them, and then you can resave the text area and hopefully it will be all good :)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...