Get parameters from answer sheet link: Difference between revisions
From Catglobe Wiki
More actions
Phamngocson (talk | contribs) Created page with "== Challenge == In order to get parameter by js from answer sheet to do some purpose. How can you do that? This article will guide you to get parameter via javascript (both ..." |
(No difference)
|
Latest revision as of 13:18, 26 May 2015
Challenge
In order to get parameter by js from answer sheet to do some purpose. How can you do that?
This article will guide you to get parameter via javascript (both old and new viewer)
Solution
- Add a question to Questionnaire editor
- Go to menu Properties -> Question scripts -> Java script tab -> Input script
- Parameter has to use start with cg_ ex: cg_feedback, cg_type,...
Code on the new viewer
function getQueryVariable(variable) {
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if (pair[0] == variable) {
return pair[1];
}
}
}
Question.bind('afterShowQuestion', function(question, answerSheet, element) {
var param = getQueryVariable("cg_type");
//alert(param);
var url = "https://www.google.com.vn/"
if(param=="feedback")document.location = url;
});
Code on the old viewer
function getQueryVariable(variable) {
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if (pair[0] == variable) {
return pair[1];
}
}
}
quest.onInit = function(){
var param = getQueryVariable("cg_type");
//alert(param);
var url = "https://www.google.com.vn/"
if(param=="feedback")document.location = url;
}