Sometimes you want to run the same survey online (using a web browser) and offline (using OfflineSurveys). The advantage is that all responses will be saved at one single survey and you do not need to merge data from different surveys later. So question is “How can we use the best matching question types which can be different online and offline?” For example a barcode question available at OfflineSurveys only should become a numeric question at the online survey? Another example is the Android camera question. You can’t use that question type when running the survey with your PC’s browser so that question types has to be turned into a file upload question.
The solution to these problems is a JavaScript function called Android.getVersionCode()
- At OfflineSurveys the version code will be returned
- Whe using the web browser an exception will be thrown (because this method only exists at OfflineSurveys)
Since this may sound a little technical, we have created a demo survey OfflineSurveys or Web browser.lss That sample surveydemonstrated how to detect whether a survey is run online or offline Using OfflineSurveys. It uses the following 3 questions:
- switch: is a hidden Short-Text Question that uses the JS function:Android.getVersionCode() to set the answer text value to either offlinesurveys or web. You need to add this question to your survey only once, preferably as the first question and you can then use it for conditionally showing follow up questions using expressions like {switch.value} (this will output either offlinesurveys or web as a simple text string) or {if(switch.value==’web’,’You are using a browser’,’You are running this survey at OfflineSurveys’)} (this will output either text A or B) or even use it within JavaScrip, example:
if (LEMval(‘switch.value’) == ‘offlinesurveys’) { doOfflineLogic(); } else { doWebLogic(); }
This will call either function doOfflineLogic() or doWebLogic() which you can use for further actions. - equation: is an equation question that changes its text using equations only. It simply outputs a text like: I am running on {switch.value}
- camera: is a more complex example. It is a file upload question that uses both the Limesurvey Expression Manager syntax and JavaScript to switch between the file upload option for web browsers and the special Android multimedia question for using the device’s camera with OfflineSurveys.