简体   繁体   English

如何在定标中创建表示是否选中复选框的javascript变量?

[英]How do I create a javascript variable in qualtrics that represents if a checkbox is ticked or not?

I have this code for a popup button confirming that the respondent understands the survey will be terminated if they don't agree to the consent form: 我有一个用于弹出按钮的代码,用于确认受访者不同意同意书将终止调查:

Qualtrics.SurveyEngine.addOnReady(function()
{
 /*Place your JavaScript here to run when the page is fully displayed*/
const that=this;
    this.hideNextButton();
    var btn = jQuery('<div id="Buttons"><input id="CustomButton" class="NextButton Button"  title="  Next  " type="button" name="NextButton" value=" Next  "  aria-label="Next"></div>')
    jQuery('#Buttons').append(btn);

    jQuery('#CustomButton').on('click', function(){
        var txt;
        var e= jQuery("[id='QID107']").val()
        if(e==""){
                    var r = confirm("The survey will be terminated if you do not agree with the consent form. Are you sure you wish to continue?");
                     if (r == true) {
                            that.clickNextButton();
                     } else {

                    }
        }
    });
});

I'm a novice in javascript and would like to have the variable e to refer to the choice of question QID107 which is a single checkbox for the consent form. 我是javascript的新手,希望使用变量e来指代问题QID107的选择,该问题是同意书的单个复选框。 I only want the popup with the message "The survey will be terminated (...). Are you sure you wish to continue?" 我只希望弹出消息为“调查将终止(...)。确定要继续吗?”。 to be displayed if the checkbox is left unticked and e is empty. 如果未选中该复选框并且e为空,则显示此字段。 That is what I'm trying to do with if e=="" . if e==""那就是我要处理的事情。 It looks like that condition is true regardless of the answer to the consent question, so I think I'm doing something wrong but don't know what. 无论同意问题的答案如何,该条件看起来都是正确的,所以我认为我做错了事,但不知道是什么。 How do I create that condition in this script? 如何在此脚本中创建该条件? How do I correctly get the response to the consent form into e ? 我如何正确地将对同意书的答复放入e

EDIT: The question has a condition that terminates the survey if the checkbox is left empty, so that.clickNextButton() when the checkbox is empty activates that termination condition. 编辑:如果复选框为空,则问题的条件是终止调查,因此,如果复选框为空,则that.clickNextButton()会激活该终止条件。

Instead of checking equality for 'e' with empty string you have to check it's checked state. 不必检查带有空字符串的'e'的相等性,而必须检查它的检查状态。

jQuery("[id='QID107']").is(":checked")

This return the state of checkbox, with this you get to know that checkbox is checked or not 这将返回复选框的状态,由此您将知道复选框是否已选中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Qualtrics问题文本中创建全局变量? - How do I create a global variable in Qualtrics Question Text? 验证复选框打勾 - validating checkbox ticked with javascript 当另一个复选框被勾选时,如何禁用该复选框,当未勾选该复选框时又如何重新启用? - How do I disable a checkbox when another checkbox is ticked & re-enable when unticked? 如何将复选框值(勾选或未勾选)放入 jquery/ajax 变量中? - How can I get a checkbox value (ticked or unticked) into jquery / ajax variable? Javascript复选框验证不检查是否已勾选 - Javascript Checkbox Validation not Checking if Ticked 载入错误时勾选了Javascript复选框 - Javascript Checkbox Ticked on Load Error 每次勾选某个复选框时,如何向 JS 变量添加一个? - How to add one to a JS variable each time a certain checkbox is ticked? 如果在Sharepoint Designer上选中了复选框,如何显示div? - How can I show a div if checkbox is ticked on Sharepoint designer? 勾选后如何删除复选框? - How to delete a checkbox when it is ticked? (如何)我可以告诉我的 JavaScript 到 append 一个变量/列到 Qualtrics 导出的数据吗? - (how) can I tell my JavaScript to append a variable/column to the data Qualtrics exports?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM