I have one Text Box (also called "Text Entry") in my qualtrics survey in which I want participants to write something but I do not want to have the result saved in my data. I do not want to use the password function, therefore I have used JavaScript at the Text Box level.
The code below works to the extent that whatever participants put in the Text Box it will be set to an empty string the moment they hit the Next-Button.
Qualtrics.SurveyEngine.addOnload(function()
{
/*Place Your Javascript Below This Line*/
var currentQuestionID = this.getQuestionInfo().QuestionID
var input = $("QR~"+currentQuestionID);
$('NextButton').onclick = function (event) {
input.value = ""
}
});
The problem: This code only works sometimes. For example when I have two textboxes with the exact same code it only works for the first but not the second one. Similarly for some reason if the textbox is embedded in some other questions it doesn't work either.
Does anybody know how I can make this work either by changing my code or with a completely different solution? Essentially, I just want participants to entry some text which will never be saved in my data and I cannot use the password function.
Solution: One way of solving this would be adding a "Descriptive Text" item in which you can add some simple HTML code:
<p>Please provide your email address:</p><p><br></p>
<input name="nothing" type="textarea">
I don't think JavaScript works well in this case as it can't be guaranteed to run before the page has sent the data.
The best way is to make a dummy HTML "question" which has the appearance of a form but does not save any information.
I tried this out in a test survey by adding a question of type "Descriptive Text", and then in "HTML View" for that question, adding:
<p>This is not a real question, there is just a HTML textarea. </p>
<form id="mydummyform">
<input name="nothing" type="textarea" />
</form>
I found that this sometimes showed the HTML source instead of the form in the survey editor; if it does this, just go to "HTML View" and then "Normal View" and it should resolve correctly. This problem was only in the editor -- it always showed correctly in a preview of the survey.
Related
I'm trying to fill in a form by pasting javascript into the debug console but although the data shows up on screen, the form still gives errors about being empty.
Is there a way to update an online form with javascript per element? I've seen people do it with a submit:
document.getElementById("firstName").value="Username";
document.forms[0].submit()
But I need the page to update after certain items because it will offer different fields in response. Also, I don't think there is an HTML form in the code because I get this response:
console.log(document.getElementById("firstName").form.id)
<empty string>
Could I do something (functionally) like this:
document.getElementById('firstName').value = 'myname';
document.getElementById('firstName').submit();
(I know this is not valid code, but I no idea how else to explain myself:( )
One of the problems is that just setting the name makes it show up on screen, but when I press the pay button on the page it simply says the name is still not filled in. I then have to click the name field, type a space, press return, and then the name is finally 'seen', but with an extra space.
if the firstName input is just a child element of the form, you can try
console.log(document.getElementById("firstName").parentNode.id);
document.getElementById('firstName').value = 'myname';
document.getElementById('firstName').parentNode.submit();
I've been struggling with this for a long time and finally have half a solution but not the rest.
Basically, I need Qualtrics respondents to enter a number input into a textbox inline, and I want to store that input as Embedded Data.
So far, in the html of the Qualtrics page, I have
Enter data here: <input type="text" id="myText" value=" ">
<input type="submit" value="Confirm" onclick="formdata()"/>
<script>
function formdata(){
var questionanswer= document.getElementById("myText").value;
Qualtrics.SurveyEngine.setEmbeddedData("Q1input", questionanswer);
}
</script>
This works fine. It creates the text box where they can enter "myText," and then it stores this as Embedded Data Q1input, which I can then access later. However, it's annoying because they have to click this "Confirm" button I created and then leave the page using the normal Qualtrics Next Page button. I did this because I couldn't get it to work at all by running this when the Qualtrics Next Button was clicked, so I had to make it run on my own button.
I've tried to disable the Next Page buttons using the disableNextButton and clickNextButton Qualtrics code, but I don't know where to put it. I can disableNextButton by putting the code in the addOnload portion, but I can't seem to get clickNextButton to run in the formdata function.
Any help would be greatly appreciated! I don't really know JavaScript; I'm just trying to pick this up to run a survey.
The easiest way to handle this is actually just to call your function any time the text entry field changes. Since Qualtrics includes PrototypeJS, you can use the following:
Enter data here: <input type="text" id="myText" value=" ">
<script>
function formdata(){
var questionanswer= document.getElementById("myText").value;
Qualtrics.SurveyEngine.setEmbeddedData("Q1input", questionanswer);
}
$('myText').observe('change', formdata());
</script>
Two thoughts here:
You should be including your script in the JavaScript section of your question, rather than the html edditor. It belongs in the addOnReady Section.
Qualtrics.SurveyEngine.addOnReady(function()
{
function formdata(){
var questionanswer= document.getElementById("myText").value;
Qualtrics.SurveyEngine.setEmbeddedData("Q1input", questionanswer);
}
$('myText').observe('change', formdata());
});
You could achieve the same effect by using a text entry question type in Qualtrics, then using piped-text to add it to the embedded data field in your survey flow.
I am trying to password protect some text in a Blogger blogpost and I found a website that explains how to do so.
I had to add this line of code between my <head> tags in the html template:
<script type="text/javascript" src="http://www.vincentcheung.ca/jsencryption/jsencryption.js"></script>
And once that's done I just need to:
copy the text from the blogpost I want to password protect into their box here → http://www.vincentcheung.ca/jsencryption/
Type my password in their Key box
Copy the HTML code provided in their last box.
This is the basic code used in the body of the html code of my blogpost to do the decryption:
<div id="uniqueID" title="encrypted text">
Show encrypted text
</div>
And I can easily change the text "Show encrypted text" by anything else I like.
However, once people click in the 'Show encrypted text' link, a box pops out, with some text:
And I would like to change that and do not know how to do so, since I don't know any JavaScript at all.
In the instructions, it says:
You can change the message in the dialog box that asks for the key by providing the desired message as a second parameter, eg. decryptText('uniqueID', 'Enter the password:')
But I don't really know where to add it. I have tried, but nothing seems to work.
Here is the website: http://www.vincentcheung.ca/jsencryption/instructions.html
You have this inserted in your page:
Show encrypted text
Just add a second parameter to that function call with your custom question:
Show encrypted text
I'm making a game and I've a html text box, <form> <input> </form> where the users will type in a number and submit it using a html button <button>. How do I get the number using JavaScript so I can use it in my game.js so I'll know how many lives the user want when the submit button is pressed?
I'm not quite sure if this is the correct approach but I was thinking getting the id of the <input> tag and then for the JavaScript part I would use .getElementById of some sort? However, I'm not sure how to incorporate the submit button so that only when it's pressed, I will receive what the user inputted.
Or is there another better way to do this? And if possible, can you provide an example of the codes for doing this?
Let me know if any clarification is needed, thanks!
There are multiple ways to do what you are asking for, one way to do it is as cristian has shown in the comment(using jquery).
In this jsfiddle page I've shown a sample way to do it just using javascript.
The code used in the page is as shown below:
document.getElementById("submit").onclick = function(){
var a = document.getElementById("input").value;
alert("The entered value is: "+a);
}
I need a simple script that gives me a button that when clicked will copy the contents of a text input box to the clipboard. Or it could be a script that when you click on the text input box, automatically copies the contents to the clipboard and displays a "Copy" message next to the text input box.
I've seen them all over the web, but can't find the code for one now.
This example uses jQuery:
Assuming an input box with an id of foo, and a button with an id of clickme, here's how I'd do it:
var inputText = "";
$("#clickme").click(function() {
inputText = $("#foo").val();
});
// inputText now has the input box's value
Edit:
After your clarification, I now understand what you are trying to do. Unfortunately, flash 10 broke most of the methods to do this. However, some great people wrote ZeroClipboard, which is fully compatible with flash 10 and makes it really easy to accomplish this task. Their wiki explains usage.