Have an idea?

Visit Sawtooth Software Feedback to share your ideas on how we can improve our products.

Tooltip in Javascript / Reference with ListLabel

Hi everybody,

I have a question regarding implementing a tooltip into a Javascript code.
My Javascript code looks as follows:

<script type="text/javascript">

<!--

var Item = "[%ListLabel(CBRSelectionRowList,2 %]";

document.write("<b>You indicated that you would be willing to pay $ XX for the Service "+Item+"</b>")

//-->

</script>


As you can see I want to refer to the second item in the list CBRSelectionRowList. The code for this second item includes a tooltip, which I want to be shown in the Javascript code as well.
You can see the code for the second item from the list below:

<span class="tool_tip_link" style="font-weight:300"><u><b>Datasets</b></u></span><div class="tool_tip_text" style="text-align: left;width: 1000px;height:auto;background-color:white;border:gray;font-size:14px"><u>Datasets</u> <br> <br>
• Description</div>


Now, the problem is, that with this code nothing is shown when I have a look at the final questions (Just empty where "Datasets" with a tooltip is supposed to be). Probably the code for the second item does not fit into the javascript code? Has someone an idea how to solve this problem in order to have a tooltip (hover) for "Datasets" in the question?

Thanks in advance,
Best
asked Nov 20 by TheCoder1992 (120 points)

1 Answer

0 votes
The problem is a matter of special characters going from Sawtooth Script to JavaScript.  If you look at your browser's console on this page, you should see an error message point out the JavaScript engine dying on line 5 of your code:

var Item = "<span class="tool_tip_link" style="font-weight:300"><u><b>Datasets</b></u></span><div class="tool_tip_text" style="text-align: left;width: 1000px;height:auto;background-color:white;border:gray;font-size:14px"><u>Datasets</u>  
• Description</div>";


Escaping the quotation marks in your list item label with a backslash would be one way to fix this, but that may not be an option for you if you want to display this list item normally in the survey elsewhere.  The easiest way to address this would be to instead have line 5 of your script use apostrophes instead of quotation marks.

The new line character in the list item label will also trip up the JavaScript.  I would recommend just removing that and making your item a single line.

P.S.: You're missing a close paren with your ListLabel call.
answered Nov 20 by Zachary Platinum Sawtooth Software, Inc. (156,375 points)
...