Millisecond Forums

Prevent Duplicate Data in Ranking Items for Survey

https://forums.millisecond.com/Topic31294.aspx

By bjohns47@masonlive.gmu.edu - 4/11/2021

I have just started using Inquisit 6 and have no experience with the prior versions or with C scripting, I am developing a survey that requires respondents to rank 10 items, 1 through 10.using a dropdown list. I have ensured that all items are ranked before proceeding by using /required = true for each dropdown; however, I have not been able to determine how to ensure that each item has a separate and different ranking to the other items, i.e. no duplicate rankings. Is this possible in Inquisit 6, and if so, how would I script this requirement? Each ranking, 1 through 10, must be used before proceeding and no items may have the same ranking.

Thanks for any helpful solutions.
By Dave - 4/12/2021

I have just started using Inquisit 6 and have no experience with the prior versions or with C scripting, I am developing a survey that requires respondents to rank 10 items, 1 through 10.using a dropdown list. I have ensured that all items are ranked before proceeding by using /required = true for each dropdown; however, I have not been able to determine how to ensure that each item has a separate and different ranking to the other items, i.e. no duplicate rankings. Is this possible in Inquisit 6, and if so, how would I script this requirement? Each ranking, 1 through 10, must be used before proceeding and no items may have the same ranking.

Thanks for any helpful solutions.

See e.g. https://www.millisecond.com/forums/FindPost7524.aspx
By bjohns47@masonlive.gmu.edu - 4/12/2021

Dave,

That was very helpful and prevents the survey from continuing if a ranking is duplicated. When a duplicate occurs all the dropdown rankings are changed back to blanks. Is there script I could modify that would just flag the duplicate dropdown rankings, something similar to what occurs with the / required field where the first dropdown that has no ranking is flagged by changing the font color of the dropdown to red without restarting the survey?

Again, thank you very much for your helpful and quick reply.
By Dave - 4/12/2021

Dave,

That was very helpful and prevents the survey from continuing if a ranking is duplicated. When a duplicate occurs all the dropdown rankings are changed back to blanks. Is there script I could modify that would just flag the duplicate dropdown rankings, something similar to what occurs with the / required field where the first dropdown that has no ranking is flagged by changing the font color of the dropdown to red without restarting the survey?

Again, thank you very much for your helpful and quick reply.

Figuring out which exact rank numbers were duplicated or triplicated, etc. would be a huge pain (you'd have to compare every dropdown's response to every other dropdown's response), but you can keep the previous choices around and print out a more general error message like so:

<values>
/ rankstring = ""
/ validranking = false
/ d01_prev = 0
/ d02_prev = 0
/ d03_prev = 0
/ d04_prev = 0
/ errormessage = ""
</values>

<block myblock>
/ trials = [1=mypage]
</block>

<surveypage mypage>
/ caption = "Assign rank numbers below."
/ subcaption = "<font color=~"#FF0000~"><%values.errormessage%></font>"
/ questions = [1=d01; 2=d02; 3=d03; 4=d04]
/ ontrialbegin = [values.rankstring=""]
/ ontrialend = [values.rankstring=concat(values.rankstring,dropdown.d01.selectedcaption)]
/ ontrialend = [values.rankstring=concat(values.rankstring,dropdown.d02.selectedcaption)]
/ ontrialend = [values.rankstring=concat(values.rankstring,dropdown.d03.selectedcaption)]
/ ontrialend = [values.rankstring=concat(values.rankstring,dropdown.d04.selectedcaption)]
/ ontrialend = [
    values.d01_prev = dropdown.d01.response;
    values.d02_prev = dropdown.d02.response;
    values.d03_prev = dropdown.d03.response;
    values.d04_prev = dropdown.d04.response;
]
/ ontrialend = [if (contains(values.rankstring,"1")==true && contains(values.rankstring,"2")==true && contains(values.rankstring,"3")==true && contains(values.rankstring,"4")==true) {
        values.validranking = true;
    } else {
        values.validranking = false;
        values.errormessage = "Not all ranks have been uniquely assigned. Please revise your responses."
    };
]
/ branch = [if ( values.validranking == false) surveypage.mypage]
/ showpagenumbers = false
/ showquestionnumbers = false
</surveypage>

<dropdown d01>
/ options = ("1", "2", "3", "4")
/ defaultresponse = values.d01_prev
</dropdown>

<dropdown d02>
/ options = ("1", "2", "3", "4")
/ defaultresponse = values.d02_prev
</dropdown>

<dropdown d03>
/ options = ("1", "2", "3", "4")
/ defaultresponse = values.d03_prev
</dropdown>

<dropdown d04>
/ options = ("1", "2", "3", "4")
/ defaultresponse = values.d04_prev
</dropdown>



By bjohns47@masonlive.gmu.edu - 4/12/2021

Dave,

Thank you.

Absolutely wonderful and works great. Just incase someone else may use something like this, there was a small error in the subcaption at the end when /font was used. The following seems to work:

/subcaption = "<font color=~"#FF0000~"><%values.errormessage%></font color>"

How would I include an error message when a dropdown has not been selected? At this time the system automatically changes the text to red for the first question without a ranking , but no message is displayed.

Thanks again for all your help.
By Dave - 4/12/2021

Dave,

Thank you.

Absolutely wonderful and works great. Just incase someone else may use something like this, there was a small error in the subcaption at the end when /font was used. The following seems to work:

/subcaption = "<font color=~"#FF0000~"><%values.errormessage%></font color>"

How would I include an error message when a dropdown has not been selected? At this time the system automatically changes the text to red for the first question without a ranking , but no message is displayed.

Thanks again for all your help.

> How would I include an error message when a dropdown has not been selected?

In pretty much the same way.

<values>
/ rankstring = ""
/ validranking = false
/ d01_prev = 0
/ d02_prev = 0
/ d03_prev = 0
/ d04_prev = 0
/ errormessage = ""
</values>

<block myblock>
/ trials = [1=mypage]
</block>

<surveypage mypage>
/ caption = "Assign rank numbers below."
/ subcaption = "<font color=~"#FF0000~"><%values.errormessage%></font>"
/ questions = [1=d01; 2=d02; 3=d03; 4=d04]
/ ontrialbegin = [values.rankstring="";]
/ ontrialend = [values.rankstring=concat(values.rankstring,dropdown.d01.selectedcaption)]
/ ontrialend = [values.rankstring=concat(values.rankstring,dropdown.d02.selectedcaption)]
/ ontrialend = [values.rankstring=concat(values.rankstring,dropdown.d03.selectedcaption)]
/ ontrialend = [values.rankstring=concat(values.rankstring,dropdown.d04.selectedcaption)]
/ ontrialend = [
    values.d01_prev = dropdown.d01.response;
    values.d02_prev = dropdown.d02.response;
    values.d03_prev = dropdown.d03.response;
    values.d04_prev = dropdown.d04.response;
]
/ ontrialend = [if (contains(values.rankstring,"1")==true && contains(values.rankstring,"2")==true && contains(values.rankstring,"3")==true && contains(values.rankstring,"4")==true) {
        values.validranking = true;
    } else {
        values.validranking = false;
        values.errormessage = "Not all ranks have been uniquely assigned. Please revise your responses.";
        if(dropdown.d01.response == "" || dropdown.d02.response == "" || dropdown.d03.response == "" || dropdown.d04.response == "") {
            values.errormessage = concat(values.errormessage, "<br>Please answer all questions.");
        }
    };
]
/ branch = [if ( values.validranking == false) surveypage.mypage]
/ showpagenumbers = false
/ showquestionnumbers = false
</surveypage>

<dropdown d01>
/ options = ("1", "2", "3", "4")
/ defaultresponse = values.d01_prev
/ required = false
</dropdown>

<dropdown d02>
/ options = ("1", "2", "3", "4")
/ defaultresponse = values.d02_prev
/ required = false
</dropdown>

<dropdown d03>
/ options = ("1", "2", "3", "4")
/ defaultresponse = values.d03_prev
/ required = false
</dropdown>

<dropdown d04>
/ options = ("1", "2", "3", "4")
/ defaultresponse = values.d04_prev
/ required = false
</dropdown>

By bjohns47@masonlive.gmu.edu - 4/12/2021

Thank you again. I would not have thought to set the dropdown required to false. All works great.