2

I'm using the following code to modify the form answer:

$('QR~QID24~1').insert({after: ' out of'});
$('QR~QID24~2').style.position = "relative";
$('QR~QID24~2').style.left = "100px";
$('QR~QID24~2').style.bottom = "34.5px";

This doesn't work anymore because when the block is looped the question is repeated five times, with the following names:

QR~1_QID24~1

QR~2_QID24~1

QR~3_QID24~1

QR~4_QID24~1

QR~5_QID24~1

I tried to repeat the code with every name:

$('QR~1_QID24~1').insert({after: ' out of'});
$('QR~1_QID24~2').style.position = "relative";
$('QR~1_QID24~2').style.left = "100px";
$('QR~1_QID24~2').style.bottom = "34.5px";

$('QR~2_QID24~1').insert({after: ' out of'});
$('QR~2_QID24~2').style.position = "relative";
$('QR~2_QID24~2').style.left = "100px";
$('QR~2_QID24~2').style.bottom = "34.5px";

and so on... But that just doesn't work. I've looked but not been able to find a solution to the identification of question in looped blocks.

niklai
  • 376
  • 3
  • 16

2 Answers2

1

Try this:

var qid = this.questionId;
$('QR~'+qid+'~1').insert({after: ' out of'});
$('QR~'+qid+'~2').style.position = "relative";
$('QR~'+qid+'~2').style.left = "100px";
$('QR~'+qid+'~2').style.bottom = "34.5px";

I think your solution didn't work because only some of the elements exist on each page, so the one's that don't exist are causing an error. You would have to put an if statement in front of each one to avoid the error.

T. Gibbons
  • 4,919
  • 2
  • 15
  • 32
1

Just for the record. A final solution in this case involves getting the PostTag code, which changes in each of the loops.

var currentPostTag = this.getPostTag();

    $('QR~'+currentPostTag+'~1').insert({after: ' out of'});
    $('QR~'+currentPostTag+'~2').style.position = "relative";
    $('QR~'+currentPostTag+'~2').style.left = "90px";
    $('QR~'+currentPostTag+'~2').style.bottom = "28px";
Gorka
  • 3,555
  • 1
  • 31
  • 37