Using custom JavaScript functions in an inline_html item
Hi,
I started using OS and OSWeb very recently, sorry if I’m missing something obvious.
With colleagues of my lab, we’re trying to set up an online experiment for which we need custom forms with multiple Likert scales to rate speech stimuli.
The creation of a form using an inline_html item is quite straightforward, here is a very basic example with a single scale to keep the sample code short:
However I was stuck at the next step when I wanted to add input control in Javascript, to make the submit button accessible only when the participant selects an option on the scale.
I wanted to do something like the code below which works fine in a HTML form (I made it as basic as possible for testing, usually I would rather use jQuery and onchange), but it gives an Application error saying that validate is undefined.
I have the same issue when trying to define the validate function in an inline_javascript item without the <script> tag before or after the inline_html item.
I finally found a workaround by copying the code of the js function on the onclick attribute of each input other than submit:
As you can see, it’s not a very convenient way to proceed, especially in the case of a more complex form with multiple inputs.
So my question is: is there another way to define JavaScript functions that will be accessible from an inline_html item, either in the same item, in another OS item or in an external .js file?
Best,
Nicolas
PS: Apologies for the embedded images, it's my 1st post here and I couldn't figure out how to include formatted code snippets
Comments
Hi Nicolas,
Unfortunately, I can't help you with your primary problem (I have never used forms online), but I can tell you have to use formatted code here. Just click on the paragraph symbol next (on the left) to the line that you are currently typing. Next click on the quotation marks, and there select `code block`
Good luck with your experiment!
Eduard
Hi Nicholas,
I have exactly the same issue you describe in this post.
Did you find a more proper solution than the one you describe in this post?
Thanks a lot
José