> @TomG said: > > @Jonas said: > > Can you give me additional hints? > ``` > Qualtrics.SurveyEngine.addOnReady(function() > { > var timeRemaining = parseInt("${e://Field/timeRemaining}"); > var input = jQuery("#"+this.questionId+" .InputText"); > > var timer = setInterval(function() { > if(timeRemaining <= 0) { > input.val('-999'); > jQuery('#NextButton').click() > } > timeRemaining--; > Qualtrics.SurveyEngine.setEmbeddedData('timeRemaining', timeRemaining); > }, 1000); > > Qualtrics.SurveyEngine.addOnUnload(function() { > clearInterval(timer); > }); > }); > ``` > > Works like a charm. Thank you so much!!
> @TomG said: > 'this' inside the setInterval function doesn't refer to the question object. Create an input variable before the function, then use the input variable inside the function to set the value. > > Don't create a duplicate setInterval function in unload. Move unload inside onload so you can refer to the timer variable. Hi Tom Thanks you for your answer. I tried around for quite some time but I am not used to JavaScript and can't get it to work. The best I came up with is this: Qualtrics.SurveyEngine.addOnload(function() { var timeRemaining = parseInt("${e://Field/timeRemaining}"); var ID = this; var timer = setInterval(function() { if(timeRemaining <= 0) { jQuery('#'+ID.questionId+'.InputText').val('-999'); $('NextButton').click() } timeRemaining--; Qualtrics.SurveyEngine.setEmbeddedData('timeRemaining', timeRemaining); }, 1000); }); It seems that the question object is not pas
> @TomG said: > > @Jonas said: > > Thank you very much for your answer. This might work. Can you share more details on how to implement it? As far as I understand it, we would have a text-box question (as it is now) and adding to the current code a hidden choice answer inside it's JavaScript menu. > If all you have is text entry questions, you can just update the value of the text input with -999 then click the next button. I was assuming you would have some MC questions. > ``` > jQuery("#"+this.questionId+" .InputText").val("-999"); > ``` > > Hi TomG Thank you, again for your answer. I tried to incorporate your feedback and ended up with this code: Qualtrics.SurveyEngine.addOnload(function() { var timeRemaining = parseInt("${e://Field/timeRemaining}"); var timer = setInterval(function() { if(timeRemaining <= 0) { jQuery("#"+this.questionId+".InputText").val("-999"); $('NextButton').click() }
> @TomG said: > To set an answer to a question, the answer has to be a choice. You would have to include your "No answer" choice in each question and hide it. > > You should move clearInterval to the unload function in case the person answers before the time expires. Hi TomG Thank you very much for your answer. This might work. Can you share more details on how to implement it? As far as I understand it, we would have a text-box question (as it is now) and adding to the current code a hidden choice answer inside it's JavaScript menu. The force response mechanism would then accept either a text-box answer or a choice answer, right? Can you share the code? Thank you so much! Jonas
You can make a displaycondition on every question which requires your TimeLeft to be > 0. If the timer is 0, it will skip all questions and you will get into the new block.
> @TomG said: > Oops, I had a mismatched quote. I updated the code in my original post. Awesome! it works perfectly!!
> @TomG said: > This will focus on the text entry box so the user can start typing without clicking on the box first (I think this is what you are asking): > ``` > jQuery("#"+this.questionId+" .InputText').select().focus(); > ``` > It seems like you could be using a single loop&merge block instead of 35 separate blocks. You would just pipe the word fragment into the question. Awesome, that is exactly what I am looking for! Since I am quite unexperienced with code I do not know how to implement it. Because: Qualtrics.SurveyEngine.addOnReady(function() { jQuery("#"+this.questionId+" .InputText').select().focus(); }); Gives me the Error: #SiteWide.Alert Invalid JavaScript! You cannot save until you fix all errors: Unexpected token ILLEGAL How to implement the code? 😀 Thanks Jonas
Already have an account? Login
Enter your username or e-mail address. We'll send you an e-mail with instructions to reset your password.
Sorry, we're still checking this file's contents to make sure it's safe to download. Please try again in a few minutes.
Sorry, our virus scanner detected that this file isn't safe to download.