Javascript and replacing values

4 years 2 weeks ago - 4 years 2 weeks ago #93348 by rodriguezm1
I want to insert values into an array question that I have created.

I want to use javascript to insert values into a question that was already answered. I want to override some values, pretty much.

Lets say I create a multi-numeric answer question called Q1.
It has two sub-questions, sq1, and sq2.

Basically, I want to, later in the survey, make Q1_sq1 equal to 1000.

I created the following javascript and don't seem to be able to get it correct. Can someone tell me what I have wrong?
<script type="text/javascript" charset="utf-8">
 	$(document).ready(function() {
        "{Q1_sq1}" = 1000;
        document.write( "The value of Q1_sq1 is {Q1_sq1} <BR>" );


I also tried this
<script type="text/javascript" charset="utf-8">
 	$(document).ready(function() {
        document.getElementById("answer{Q1_sq1}").value = 1;
        document.write( "The value of Q1_sq1 is {Q1_sq1} <BR>" );

And it still didn't work. Ideas? Am I using the wrong syntax?


This file is really what I'm working with. The above is a simplified, general example.

The Javascript is in question group "Approaches 2", question: "multi"

Its some test script. The point is, once I figure out how to write values to other arrays, then I can figure out how to make interim arrays, fill them in, and use them to filter future questions. Eventually that's what I'm getting at.

Please figure out where my syntax might be wrong. Thanks.
Last Edit: 4 years 2 weeks ago by rodriguezm1.

Please Log in to join the conversation.

4 years 2 weeks ago #93355 by helper
Did I mention how much I hate checkboxes :S

Well, now that is out of the way... let me see if I can paraphrase what you are attempting to accomplish. First off, you create a set of answers (by the way all of the questions and answers are in session) of which when you check a checkbox, you want to change the value of a previous question.

First off, a quick lesson on jQuery and the document.getElementById << translates into $("yourID") though both will work. Second, you need to capture the onClick event when a person checks the checkbox to do something (in this instance, we would want to set a value of something already set in session).

File Attachment:

File Name:
File Size:7 KB

Please Log in to join the conversation.

4 years 2 weeks ago - 4 years 2 weeks ago #93358 by rodriguezm1

Eventually what I want to do is this:

1. User enters a bunch of checkboxes in Q1, an array with 10 sub-questions, sq1 - 10.
2. I create a new, hidden array. Call it Q2. Q2 has 10 subquestions. This new hidden array will test the sum of the checkboxes.
3. If there is more than one checkbox checked for Q1_sq1, then the new array value for Q2_sq1 should be 1. If not, leave it empty.
4. I create a new question, Q3. Q3 also has 10 sub-questions. Q3 has an array filter based on Q2.

This way, only the questions where the user selects more than one checkbox is brought into Q3. Its the way I conceptualized a workaround to do this. Otherwise, I can't get Q3 to filter on Q1 with only the values that have more than one checkbox.

I have to have the in between step it seems.

This is what I'm eventually trying to do. I'm eventually trying to get a way to use array filters, but to make more customized interim arrays that populate dynamically based on some if statements.


When I populate my interim array, what jQuery or javascript command should I use?

I want something like:

Remember, Q1 is my original array of checkboxes.
Q2 a new multi number question.
var thesum;
thesum = sum(${that.Q1.sq_sq1.NAOK});
if( thesum >1)
$({Q2.sq1}) = 1;

Finally, Q3 is created. It is, say, a 5-point array. It has an array filter based on Q2.

Thus, Q3 effectively has an array filter based on the answers in Q1 that have more than one box checked.

My syntax is probably all sorts of wrong. Can you help me with that?
Last Edit: 4 years 2 weeks ago by rodriguezm1.

Please Log in to join the conversation.

4 years 2 weeks ago #93359 by rodriguezm1
In other words, my issue is that array filters are binary. It filters only if the sub-question for a previous answer has, or does not have, an answer.

I am trying this workaround so that I can have a more conditional array filter. So that way, its an array filter based on an if() statement, not just whether or not there is a value.

Suppose I have an array of 5-point questions. I want a subsequent array filter to only show questions rated 4 and above.

I can't do that with a simple array filter. I have to create an interim array, fill in the array with binaries, and then filter based on the interim array.

See what I'm doing and how I'm thinking?

Please Log in to join the conversation.