使用谷歌应用脚本和谷歌网站,我试图写下一个表格并在电子表格中获得答案。这是我现在的工作:
function doGet(){
var app = UiApp.createApplication().setTitle('Radio Button Demo');
var radio1 = app.createVerticalPanel();
var radio11 = app.createRadioButton('group1','Oui').setName('oui1').setId('oui1');
var radio12 = app.createRadioButton('group1','Non').setName('non1').setId('non1');
radio1.add(radio11).add(radio12);
app.add(radio1);
var radio2 = app.createVerticalPanel().setId('question2').setVisible(false);
var radio21 = app.createRadioButton('group2','Oui').setName('oui2').setId('oui2');
var radio22 = app.createRadioButton('group2','Non').setName('non2').setId('non2');
radio2.add(radio21).add(radio22);
app.add(radio2);
var radio3 = app.createVerticalPanel().setId('question3').setVisible(false);
var radio31 = app.createRadioButton('group3','Oui').setName('oui3').setId('oui3');
var radio32 = app.createRadioButton('group3','Non').setName('non3').setId('non3');
radio3.add(radio31).add(radio32);
app.add(radio3);
var radio4 = app.createVerticalPanel().setId('question4').setVisible(false);
var radio41 = app.createRadioButton('group4','Cool').setName('oui4').setId('oui4');
var radio42 = app.createRadioButton('group4','Or not').setName('non4').setId('non4');
radio4.add(radio41).add(radio42);
app.add(radio4);
// handler to make value of question 1 change
var handler11 = app.createServerValueChangeHandler('showstatus1_1');
handler11.addCallbackElement(radio1);
radio11.addValueChangeHandler(handler11);
var handler12 = app.createServerValueChangeHandler('showstatus1_2');
handler12.addCallbackElement(radio1);
radio12.addValueChangeHandler(handler12);
// handler to make value of question 2 change
var handler21 = app.createServerValueChangeHandler('showstatus2_1');
handler21.addCallbackElement(radio2);
radio21.addValueChangeHandler(handler21);
var handler22 = app.createServerValueChangeHandler('showstatus2_2');
handler22.addCallbackElement(radio2);
radio22.addValueChangeHandler(handler22);
// handler to make value of question 3 change
var handler31 = app.createServerValueChangeHandler('showstatus3_1');
handler31.addCallbackElement(radio3);
radio31.addValueChangeHandler(handler31);
var handler32 = app.createServerValueChangeHandler('showstatus3_2');
handler32.addCallbackElement(radio3);
radio32.addValueChangeHandler(handler32);
// handler to make value of question 4 change
var handler41 = app.createServerValueChangeHandler('showstatus4_1');
handler41.addCallbackElement(radio4);
radio41.addValueChangeHandler(handler41);
var handler42 = app.createServerValueChangeHandler('showstatus4_2');
handler42.addCallbackElement(radio4);
radio42.addValueChangeHandler(handler42);
// functions to change values of question 1
function showstatus1_1(e){
var app = UiApp.getActiveApplication();
var radioValue = e.parameter.oui1
app.getElementById('non1').setValue(false);
app.getElementById('question2').setVisible(true);
return app;
}
function showstatus1_2(e){
var app = UiApp.getActiveApplication();
var radioValue = e.parameter.non1;
app.getElementById('oui1').setValue(false);
app.getElementById('question2').setVisible(true);
return app;
}
// functions to change values of question 2
function showstatus2_1(e){
var app = UiApp.getActiveApplication();
var radioValue = e.parameter.oui2
app.getElementById('non2').setValue(false);
return app;
}
function showstatus2_2(e){
var app = UiApp.getActiveApplication();
var radioValue = e.parameter.non2;
app.getElementById('oui2').setValue(false);
return app;
}
// functions to change values of question 3
function showstatus3_1(e){
var app = UiApp.getActiveApplication();
var radioValue = e.parameter.oui3
app.getElementById('non3').setValue(false);
return app;
}
function showstatus3_2(e){
var app = UiApp.getActiveApplication();
var radioValue = e.parameter.non3;
app.getElementById('oui3').setValue(false);
return app;
}
// functions to change values of question 4
function showstatus4_1(e){
var app = UiApp.getActiveApplication();
var radioValue = e.parameter.oui4
app.getElementById('non4').setValue(false);
return app;
}
function showstatus4_2(e){
var app = UiApp.getActiveApplication();
var radioValue = e.parameter.non4;
app.getElementById('oui4').setValue(false);
return app;
}
我的第一个问题是如何根据问题 1 和 2 的答案使问题 3 和 4 可见。我已经根据 1 个问题的答案找到了如何做到这一点,但我遇到了多个问题。例如:如果答案是“Oui”和“Oui”,则使问题 3 可见,否则使问题 4 可见!
我的第二个问题是:如何获得不同问题的值?我想在现有的电子表格中写下不同用户的答案以及选择。但是当我试图找到一种获取用户答案的方法时,我被困住了。
谢谢你有时间帮助我,文森特