Difficulty to access pool file using javascript
Hi! I'm developing an experiment that has, as one of its phases, kind of a preference test. The choices are between 48 png images. At the end of this phase, the application shows to the participants their top 3 favorite images. The top 3 are showed in individual screens, 1 by 1, that where made using inline_html item. It can not be made through a sketchpad, because the participants will need to confirm their agreement with the results, in a likert scale, at the same screen.
The problem is that the <img scr> html tag is not showing the image, even though the console shows that's everything ok. I've been trying to access the image in the pool, to inform to the complete image path to the html code, but I had no success, despite 3 days of million different tries.
I've being trying specially the orientations available on 332 and 7279 topics. But it's like the "file" attribute is not working anymore (and I really dind't find it at the js files). I'm using OpenSesame 3.3.14 and OSWeb 1.4.13.1.
Is there any other way to do this, and bring the complete path of the image at the pool to a variable?
Tks a lot!
Comments
Hi @conrado ,
Here's an example of how you can do this in an
inline_htmlitem in the upcoming OpenSesame 4.0.<img>tag with anidthat we can refer to ('target_img').dataproperty of that file-pool object is itself an object (a JavaScript object is equivalent to an tag.)srcproperty from the file-pool object to the newly created<img>tag.It's not very elegant, but do you see the logic?
<input type='text' name='text_response'> <img id="target_img"> <input type='submit' value='ok'> <script> # This gets the IMG element const targetImg = document.getElementById('target_img') # pool['pupil-cat.jpg'].data is also an image element # we can assign the source to the target-image source # to make the image visible targetImg.src = pool['pupil-cat.jpg'].data.src </script>Hope this helps!
— Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Thanks, @sebastiaan!
I was very excited to try OpenSesame 4.0, and I tried last weekend, but it demands me some adaptations that I don't have time enough to do for now. I need to finish this work until Friday morning. For example, I have js scripts inside my inline_html items to review. OS 4.0 also loses some rules and conditions, when it opens an experiment developed in an older version, like the details of mouse_response item, some "run if" of sequence items and inside repeat_cycle item. It's not too much, If would not have so many of them with different parameters.
I found a solution to my problem, copying all the images to the img directory inside the zip file of my application, before upload it to a Jatos server. I made this renaming the root directory and using the entire path at the html tag, and not renaming, juts pointing to img directory. Until now, both ways are working.
But I'll keep trying a better way when I have more time, to not duplicate the 48 png images inside my application at Jatos server.
One more time, thanks a lot for your help!
=)
Hi, @sebastiaan!
I came back to tell you that today your suggestion worked very well.
In my previous attempts, I was making a wrong reference to the variable that would have the name of the image which I needed to locate in the pool. Like, the name of the image file was at img_name variable, and I wrote the code as OpenSesame generally references the variables, pool['img_name'].data.src, when the right way should be pool[vars.img_name].data.src.
That kind of silly mistake that we don't see a million times and end up naturally not making again when rewriting the code from zero.
Tks again!
=)