简体   繁体   English

如果 Gravity 表单结果不返回任何内容,则隐藏 div

[英]Hide a div if Gravity form results return nothing

I have a Gravity form which is being used as an assessment.我有一个重力表,它被用作评估。 Users click checkboxes that are relevant to them and the confirmation page shows different groups they qualify for (due to the checkboxes that clicked).用户单击与他们相关的复选框,确认页面会显示他们符合资格的不同组(由于单击的复选框)。

If a group doesn't have any of its boxes checked, it won't appear on the submission page (the result is hidden).如果一个组没有选中任何框,则它不会出现在提交页面上(结果被隐藏)。

I'm trying to also hide a div from appearing if XYZ group doesn't appear.如果 XYZ 组没有出现,我也试图隐藏一个 div。 For example, if result1 didn't have anything checked, I want to hide div id "myid".例如,如果 result1 没有检查任何内容,我想隐藏 div id "myid"。

I've been trialling and erroring in how to get this done with php but am still learning the language and feeling a bit lost.我一直在尝试如何使用 php 完成这项工作,但我仍在学习这门语言,感觉有点失落。 I found the JS code below and thought it could be a good indication of what I'm trying to achieve.我在下面找到了 JS 代码,并认为它可以很好地表明我想要实现的目标。 I just don't know how to exactly get it.我只是不知道如何确切地得到它。

 if($result111 = '') {
        document.getElementById("myid").style.display = 'none';
    }
    else
    {
        document.getElementById("myid").style.display = 'inline';
  }

I have created an example of the task you described:我已经创建了您描述的任务的示例:

<html>

    <head>
        <title>Hide div</title>
    </head>

    <body>
        <input type="checkbox" id="choice1" name="choice1" value="1" onclick="choiceEvent()"> Choice 1 <br>
        <input type="checkbox" id="choice2" name="choice2" value="1" onclick="choiceEvent()"> Choice 2 <br>
        <input type="checkbox" id="choice3" name="choice3" value="1" onclick="choiceEvent()"> Choice 3 <br>

        <div id="results" style="display:none">
            One of the checkboxes is pressed.
        </div>

        <script>
            function choiceEvent(){

                var choice1 = document.getElementById('choice1');
                var choice2 = document.getElementById('choice2');
                var choice3 = document.getElementById('choice3');

                if(choice1.checked || choice2.checked || choice3.checked){
                    document.getElementById('results').style.display = 'block';
                } else {
                    document.getElementById('results').style.display = 'none';
                }
            }
        </script>
    </body>

</html>

I hope it helps.我希望它有所帮助。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM