Concatenating Strings

PennController for IBEX Forums Support Concatenating Strings

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #6996
    dgetty
    Participant

    Hi Jeremy,

    I’m running a PCIbex study via mTurk, and I’m trying to append a global variable “pID” to a URL (code below). However, I can’t seem to figure out how to make this work, as the only thing that shows up in the URL is “[object%20Object]” and not the actual value of the “pID” variable. I’m sure it’s something obvious, but I can’t seem to figure out why this is not working.

    newText("<p><a href='https://pitt.co1.qualtrics.com/jfe/form/SV_9suLiT1t7sABeDg?id="+ newText("ID").text( getVar("pID") ) +"' target='_blank' rel="noopener noreferrer">Click here to complete a brief survey on Qualtrics.</a></p>")
        .center()
        .print()

    Thanks in advance!

    -Doug

    #6998
    Jeremy
    Keymaster

    Hi Doug,

    PennController elements, and Text elements in particular, are not strings, so you cannot just concatenate them to a string with +. More info here: https://doc.pcibex.net/how-to-guides/using-javascript/

    Here’s how to achieve what you need:

    newVar("link")
      .set(getVar("pID"))
      .set(v=>"<p><a href='https://pitt.co1.qualtrics.com/jfe/form/SV_9suLiT1t7sABeDg?id="+v+"' target='_blank' rel='noopener noreferrer'>Click here to complete a brief survey on Qualtrics.</a></p>")
    ,
    newText("")
      .text(getVar("link"))
      .center()
      .print()

    Jeremy

    #6999
    dgetty
    Participant

    Ahh, that makes sense. Thanks for the solution (it works perfectly!), and for the info on JavaScript.

    -Doug

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.