Helpful inline html for anyone trying to implement a Likert scale
I am a recent user of OpenSesame (switched from PsychoPy and I cannot tell you how much I love this product!!! Thank YOU to the creators and contributors)
I finally managed to create a Likert scale that suited my purpose. It took me a while to figure this out so posting it here in case others are struggling too.
As you may recall there is no easy way to create radio buttons or even buttons on the forms and users must click submit in order to proceed. This is problematic in case you want to measure response times. Also in my case I wanted to give users the option to either click a button or enter a number directly through keyboard and both would be recorded as the same response. Here's how I did it with an inline html element.
- I created a "hidden" submit button
- Used scripting to programmatically "click" the submit button after recording the response.
- I also added another inline_javascript to set document.onkeydown = null; (so that the keydown doesn't trigger on subsequent screens).
Works like a charm!!!
<script> document.onkeydown = function(key){ reactKey(key); } function reactKey(evt) { console.log(evt.keyCode); vars.buttonresp = evt.keyCode - 48; document.getElementById('sub').click(); } function clickkey(x) { vars.buttonresp = x; document.getElementById('sub').click(); } </script> <input type='button' name="opt1" value="1" onclick="clickkey(1)"> <input type='button' name="opt2" value="2" onclick="clickkey(2)"> <input type='button' name="opt3" value="3" onclick="clickkey(3)"> <input type='button' name="opt4" value="4" onclick="clickkey(4)"> <input type='button' name="opt5" value="5" onclick="clickkey(5)"> <input type='button' name="opt6" value="6" onclick="clickkey(6)"> <input type='button' name="opt7" value="7" onclick="clickkey(7)"> <input type="submit" name="sub" id='sub' style="display:none">
Here's the reset code which is an inline_javascript (not HTML)
document.onkeydown = null;
Comments
Hi @vidya ,
Thanks for sharing this, and I'm happy to hear that you enjoy working with OpenSesame!
— Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!