英文:
How to combine multiple display conditions in Perl/HTML in a multiple choice survey
问题
我正在设计一个调查问卷,它是用HTML/CSS编写的,使用了Perl逻辑。
在开始处有一个筛选问题(q1),有三个答案:
- 一次车祸(broad_screen_1)
- 糖尿病诊断(broad_screen_2)
- 癌症诊断(broad_screen_3)
- 心脏病诊断(broad_screen_4)
- 以上都不是(broad_screen_5)
在代码中,答案被记录为(1='未选择',2='已选择')。这是多项选择。
我希望在调查问卷的屏幕外部分中,如果满足以下条件之一,则显示屏幕外部分:
- broad_screen_3未被选择($broad_screen_3 !=2)
- broad_screen_5被选择($broad_screen_5 = 2)
每个显示条件单独运行时都有效,但两个条件一起不起作用。我尝试添加OR作为布尔运算符,还尝试使用逗号分隔两个参数,但都没有成功。
提前感谢。
英文:
I am designing a survey and it is written in HTML/CSS and uses Perl logic.
I have a screening question (q1) at the start which has three answers:
A car crash (broad_screen_1)
A diagnosis of diabetes (broad_screen_2)
A diagnosis of cancer (broad_screen_3)
A diagnosis of heart disease (broad_screen_4)
None of the above (broad_screen_5)
In the code, the answer is recorded as (1='not selected', 2='selected'). It is multiple choice.
I would like a screen-out section of the survey to be displayed if:
broad_screen_3 is not selected ($broad_screen_3 !=2) or if broad_screen_5 is selected ($broad_screen_5 = 2).
Each display condition works, but not together. How do I combine the two? I have tried adding OR as boolean operators, also added commas separating the two arguments but this does not work.
Thanks in advance.
答案1
得分: 1
由于您允许多项选择,答案本身不是等于3的变量。根据您的代码,它可能是一个类似于[2,3]的列表,一个类似于{2:true, 3:true}的字典,或者一个用逗号连接的字符串,如"2,3"。因此,如果有多个答案,您无法验证答案3是否等于某人的答案。
解决方法是:您可以简单地检查给定的答案中是否包含3。我们可以提供“代码特定”的答案,但您没有提供代码本身。所以这就是它的哲学。
英文:
Since you allow multiple choices, the answer itself is not a variable that equals to 3. Depending on your code it might be list like [2,3], a dictionary like {2:true, 3:true} or a string that is imploded with a comma like "2,3". So you cant verify whether the answer 3 equals to someone's answer if there is multiple.
The solution of it: You can simply check whether the 3 is in the given answer or not. We could provide mode 'code specific' answer but you did not provide the code itself. So this is the philosophy of it.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论