[Q] How to build Javascript array from survey answers

More
4 months 3 weeks ago #163011 by w14a
w14a created the topic: [Q] How to build Javascript array from survey answers
Hi, have got stuck..

Survey answers - bunch of date fields (string format, I suppose, isn't it?).
In order to find the latest date stated within the answers, at the end of the survey I need to build the array from the values of particular questions and compare the values against each other.
Javascript hypothetical fragments might look like
var bigarray = ["{Q001}", "{Q002}", "{Q00N}"];
var len=bigarray.length;
oneoftehdateis = bigarray[len];
anotherdateis= bigarray[len-1];
and so on.
My question is how to correctly build the array in Javascript and compare those values taking into account that the dates are compared, not a kind of strings. Thanks a lot!

Please Log in or Create an account to join the conversation.

More
4 months 3 weeks ago #163080 by tpartner
tpartner replied the topic: [Q] How to build Javascript array from survey answers
Try this:

<script type="text/javascript" charset="utf-8">
	$(document).ready(function(){
 
		var dates = ['{Q1}', '{Q2}', '{Q3}'];
		dates.sort();
 
		var firstDate =  dates[0];
		var lastDate = dates[dates.length-1];
	});
</script>

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: LouisGac

Please Log in or Create an account to join the conversation.

More
4 months 3 weeks ago - 4 months 3 weeks ago #163084 by w14a
w14a replied the topic: [Q] How to build Javascript array from survey answers
Thank you very much for reaction and kind response. I believe, my errors are connected with complexity of the initial task that is about to compare dates against some constants and counting them also, sorting and different formats when compared... Simply, I did not have fast scripting skill, so your help is appreciate very much ... I did not describe the whole intention initially. The Idea was to get several evaluation angles from single answer to the single question.
My scenario:
The dates in myarray[] always mean several things, so I need to interpret them by some logic: 1) Dates in a past incl. today (all should be first compared against Today, of course) should total count as numberofpastdates, 2) future dates should be total count as numberoffuturedates, plus, 3) the latest future date should be assigned to the new variable, 4) if no future dates are provided, the var x should get value false, 5) Whole empty array cells (date is not provided by respondent) should be total count as nodatesprovidednumber and, finally, 6) the particular dates, say equal to YYYY-MM-DD, should be total count as particulardatesnumber.
I have used while() and case(true) statements and expressions, but finally messed up with the script and lost in space.:( Depending on my next 3 days success, our ~3000 respondents will or will not get valuable statistical graph on their last page; btw, thanks for google graph libraries... Here is not a profitable project, only my afterhours intention to have the survey better shaped than standard "acceptable" level.
Thanks again for your kind support and invaluable ideas.
Last Edit: 4 months 3 weeks ago by w14a.

Please Log in or Create an account to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!