Have an idea?

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

JavaScript only works in free format questions

Hi all,

I have a piece of code that I'm using in a series of free format questions, and it is working correctly:

<script type="text/javascript">
<//
    jQuery(document).ready(function ()
    {
        jQuery('#next').before('<img src="[%GraphicsPath()%]/texto.png" alt="arrow" border="0">');
    });
//-->
</script>


When I want to use this code in another type of questions (e. g., select questions), it simply does not work. I've tried to put it in the "Header 1" and "Footer" sections of the question, with no results. I guess it must have to do with the inclusion of the JS library (jQuery, in this case), and so I've putted it in the "Advanced..." -> "HTML <head> tag". Still not working, though.

<link type="text/css" href="[%GraphicsPath()%]/jquery/css/ui-lightness/jquery-ui-1.8.19.custom.css" rel="Stylesheet" />
<script type="text/javascript" src="[%GraphicsPath()%]/jquery/js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="[%GraphicsPath()%]/jquery/js/jquery-ui-1.8.19.custom.min.js"></script>


I'm using version 7.0.26. Can someone please help me?

Thanks in advance,
João
asked Sep 10, 2012 by João Fernandes Bronze (2,040 points)
retagged Sep 11, 2012 by João Fernandes

2 Answers

+2 votes
can you use below code:

<script type="text/javascript">
var $jq = jQuery.noConflict();
 $jq(document).ready(function () {
    {
        $jq('#next').before('<img src="[%GraphicsPath()%]/texto.png" alt="arrow" border="0">');
    });
//-->
</script>
answered Sep 10, 2012 by Rajesh Rana Gold (23,530 points)
Hello, ranarajesh85,

I've tried that code and it's still not working (this time, I can't even choose a radio button in the select question where I've used it). I wonder why can't I do the same thing in a select question that I have already accomplished in a free format question... :S

Thanks nevertheless, if you know something more please let me know!

Regards,
João
+2 votes
With the help of Rajesh, I've managed to work out what I was doing wrong. Naively, I thought that the
jQuery.noConflict();
line (which prevents jQuery to clash with other JavaScript libraries) had only to be invoked one time per page, when in fact of course it has to be used every time a script that uses jQuery is open.

Thanks again!
João
answered Sep 13, 2012 by João Fernandes Bronze (2,040 points)
...