简体   繁体   English

显示和隐藏按钮的另一种方式

[英]Another way to show and hide buttons

The following codes works with no problem if I am running the file locally on my drive.如果我在我的驱动器上本地运行文件,以下代码可以正常工作。 Unfortunately, I need to upload this form to a software called MasterControl.不幸的是,我需要将此表格上传到名为 MasterControl 的软件。 It does not work.这是行不通的。 I was wondering if there is another way of coding that is universal to local as well as upload to a server for MasterControl.我想知道是否有另一种编码方式对本地通用以及上传到 MasterControl 的服务器。

The purpose of this code is - once you click on Yes button on the first level question then the next level questions will appear.此代码的目的是 - 一旦您在第一级问题上单击“是”按钮,就会出现下一级问题。 If you click on No button on the first level and if the questions from the next level questions showing then it will clear all the selected buttons and hide the section of the second level questions.如果您单击第一级的“否”按钮,并且显示下一级问题的问题,则它将清除所有选定的按钮并隐藏第二级问题的部分。

Here is the codes:这是代码:

HTML Code: HTML代码:

 <div id="divDeathOccurred" class="fieldRow">
        <div class="leftLabel labelWidth22">
            <label for="">A. Has a death occurred?</label>
        </div>
        <div class="leftField">
            <div class="formField34">
              <input id="rbDeathOccurred" name="rbDeathOccurred" 
      type="radio" class="radiobuttonfield" title="Death Occurred" 
      value="Yes" onclick="javascript:USAYesNoCheckDO();" />Yes
              <input id="rbDeathOccurred" name="rbDeathOccurred" 
       type="radio" class="radiobuttonfield" title="Death Occurred" 
       value="No" onclick="javascript:USAYesNoCheckDO();" />No
            </div>
        </div>
    <p>&nbsp;</p>
        <div id="USADOYesNo" style="display:none">
            <ol type="1" class="indentList">
                <li>Is there a reasonable possibility that a device failure
             or malfunction was a direct or indirect factor in the death? 
                    <br>
                    <input id="rbDOYesNo" name="rbDOYesNo" type="radio" 
            class="USDO radiobuttonfield" title="Yes Reportable" value="Yes" 
            onclick="javascript:USDeviceFailure30Days();"  />
                 <label for="rbDOYesNo" class="rptColor">Yes -
                  reportable</label>  
                    <input id="rbDOYesNo" name="rbDOYesNo" type="radio" 
                 class="USDO1 radiobuttonfield" title="No" value="No" 
                onclick="javascript:USDeviceFailure30Days();" />No - No 
               Report   
                    <div id="calc" class="indentListCalc"> 
                     <input id="dt30Days3" type="text" class="textfieldCalc 
                labelWidth25" alt="Device Malfunction" />
                    </div>
                      <p></p>                                                                  
                   </li>
                <li>Is there a reasonable possiblity that a device design 
                defect was direct or indirect factor in the death?
                    <br>
                    <input id="rbDOYesNo1" name="rbDOYesNo1" type="radio" 
           class="USDO2 radiobuttonfield" title="Yes Reportable" value="Yes"
           onclick="javascript:USDeviceDesign30Days();"/>
                    <label for="rbDOYesNo1" class="rptColor">Yes -
             Reportable</label>                     
                     <input id="rbDOYesNo1" name="rbDOYesNo1" type="radio" 
                   class="USDO3 radiobuttonfield" title="No" value="No"
               onclick="javascript:USDeviceDesign30Days();" />No - No Report 
                    <div id="calc1" class="indentListCalc"> 
                     <input id="dt30Days1" type="text" class="textfieldCalc 
                  labelWidth25" alt="Device Design" />
                    </div>
                    <p></p>
                   </li>
                 <li>Is there a reasonable possiblity that the device 
                  labeling was direct or indirect factor in the death?
                     <br>
                    <input id="rbDOYesNo2" name="rbDOYesNo2" type="radio" 
                 class="USDO4 radiobuttonfield" title="Yes Reportable"  
                value="Yes" onclick="javascript:USDeviceLabeling30Days();"/>
                 <label for="rbDOYesNo2" class="rptColor">Yes - 
                  Reportable</label>                          
                      <input id="rbDOYesNo2" name="rbDOYesNo2" type="radio" 
                class="USDO5 radiobuttonfield" title="No" value="No" 
             onclick="javascript:USDeviceLabeling30Days();"/>No - No Report 
                     <div id="calc2" class="indentListCalc"> 
                     <input id="dt30Days2" type="text" class="textfieldCalc
                  labelWidth25" alt="Device Labeling" />
                      <p></p>
                    </div>
                </li> 
            </ol>
        </div>
     </div> <!-- final section Death Occurred end --> 

Javascript Code: Javascript代码:

 function USAYesNoCheckDO() {
    if (document.getElementById('rbDeathOccurred').checked) {

       document.getElementById('USADOYesNo').style.display = 'block';

     } else {

      document.getElementById('USADOYesNo').style.display = 'none';
      document.getElementsByClassName('USDO')[0].checked = false;
      document.getElementsByClassName('USDO1')[0].checked = false;
      document.getElementById('calc').style.display = 'none';
      document.getElementsByClassName('USDO2')[0].checked = false;
      document.getElementsByClassName('USDO3')[0].checked = false;
      document.getElementById('calc1').style.display = 'none';
      document.getElementsByClassName('USDO4')[0].checked = false;
      document.getElementsByClassName('USDO5')[0].checked = false;
      document.getElementById('calc2').style.display = 'none';
     }
   }

I am still learning about all of this HTML, Javascript, and I am just getting into JQuery.我仍在学习所有这些 HTML、Javascript,而且我刚刚开始接触 JQuery。

If you need me to put these codes in jsfiddle, please let me know.如果您需要我将这些代码放在 jsfiddle 中,请告诉我。

Thank you so much,非常感谢,

IreneS艾琳

Update:更新:

I forgot to add that the codes work on the server when you select the buttons and the show and hide - the one thing does not work is the clearing the selected buttons.我忘了补充一点,当您选择按钮和显示和隐藏时,代码在服务器上工作 - 一件事不起作用是清除选定的按钮。

Thank you again.再次感谢你。

Update 2:更新 2:

After many hours of research and trying to learn Jquery, hoping that it will give me another way to get this issue resolved and get it to work on the server, unfortunately it did not.经过数小时的研究并尝试学习 Jquery,希望它能给我另一种方法来解决这个问题并让它在服务器上工作,不幸的是它没有。 The reason I was trying Jquery, because I was looking at the other forms that were on the MasterControl server, and they were coded with Jquery.我尝试使用 Jquery 的原因是,我正在查看 MasterControl 服务器上的其他表单,它们是用 Jquery 编码的。 Unfortunately, being a beginner in Jquery, I am not able to get it to work on both sides - the local drive and the server.不幸的是,作为 Jquery 的初学者,我无法让它同时在本地驱动器和服务器上工作。 Please can someone check it and see what I am missing or doing wrong.请有人检查一下,看看我遗漏了什么或做错了什么。

function getChecked(radioGroupName, index)
  {
    var oRadioList = document.getElementsByName(radioGroupName);
    return oRadioList[index].checked;
  }

function setChecked(radioGroupName, index, state)
 {
    var oRadioList = document.getElementsByName(radioGroupName);
    oRadioList[index].checked = state;
 }

function USAYesNoCheckDO()
 {
    if(getChecked("rbDeathOccured",0) == true)
    {
        $('#USADOYesNo').slideDown(1000);   
    }
    else
    {
        $('#USADOYesNo').slideUp(1000); 

        setChecked("rbDOYesNo",0,false);
        setChecked("rbDOYesNo",1,false);

        setChecked("rbDOYesNo1",0,false);
        setChecked("rbDOYesNo1",1,false);

        setChecked("rbDOYesNo2",0,false);
        setChecked("rbDOYesNo2",1,false);
    }
 }

Or if you have any idea how to get this issue fixed.或者,如果您有任何想法如何解决此问题。 As I mentioned before the buttons work and the show and hide of the questions work, the issue is when I want to reset and set it back to the original status - blank.正如我之前提到的按钮工作和问题的显示和隐藏工作,问题是我想重置并将其设置回原始状态 - 空白。

Thank you again and appreciate any help.再次感谢您并感谢您的任何帮助。

IreneS艾琳

Update 3:更新 3:

Please anybody have any thoughts/ideas on how to fix this issue.请任何人对如何解决此问题有任何想法/想法。

I really appreciate any help.我真的很感激任何帮助。

Thank you,谢谢,

IreneS艾琳

Update 4:更新 4:

Just incase someone have the same issue as I am and need a solution, I finally found a website after all this time of searching that gave me the answer and it works!以防万一有人和我有同样的问题并需要解决方案,经过这么长时间的搜索,我终于找到了一个网站,它给了我答案,并且有效! Yeh!耶! I just customized the coding to my needs and it works locally and on the server.我只是根据我的需要自定义了编码,它可以在本地和服务器上运行。

http://www.electrictoolbox.com/javascript-clear-form/ http://www.electrictoolbox.com/javascript-clear-form/

IreneS.艾琳S。

You use the same id attribute for multiple elements.您对多个元素使用相同的id属性。 id should be unique on the page, only name can be the same to group multiple input elements of the same type. id在页面上应该是唯一的,只有name可以相同才能将多个相同类型的输入元素分组。 I don't know if this is the main problem but it is a start.我不知道这是否是主要问题,但这是一个开始。

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

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