Display currently selected value of slider scale

PennController for IBEX Forums Support Display currently selected value of slider scale

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #8161
    nadine
    Participant

    Hi Jeremy,

    I’m using a slider scale and was wondering if there is any way of displaying the value to which the slider is currently set.

    Thank you!

    -Nadine

    #8164
    Jeremy
    Keymaster

    Hi Nadine,

    Here’s how to do it:

    newTrial(
        newText("scaleValue", "NA").before( newText("Score: ") )
        ,
        newScale("myScale", 7)
            .slider()
            .callback( getText("scaleValue").text(getScale("myScale")) )
            .print()
        ,
        getText("scaleValue").print()
        ,
        newButton("Next").print().wait()
    )

    Note that values start with 0, so if you want to display a score starting with 1, you’ll need to use a Var element:

    newTrial(
        newVar("scaleVar", 0)
        ,
        newText("scaleValue", "NA").before( newText("Score: ") )
        ,
        newScale("myScale", 7)
            .slider()
            .callback( 
                getVar("scaleVar").set(getScale("myScale")).set(v=>parseInt(v)+1)
                ,
                getText("scaleValue").text( getVar("scaleVar") )
            )
            .print()
        ,
        getText("scaleValue").print()
        ,
        newButton("Next").print().wait()
    )

    Jeremy

    #8168
    nadine
    Participant

    Perfect, thank you so much!

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