0

我使用LimeSurvey工具创建了一个调查。对于某些自定义,我必须执行以下任务。

截屏:

在这里,当用户点击Next并且如果有任何问题没有得到回答,我想通知用户他们错过了回答。

因此,当他们点击 时Next,我希望看到一个确认框 (Javascript),它会显示一条消息,说您错过了。会有“没关系,进入下一页”按钮和“我会留在这里回答”按钮。

“没关系,进入下一页”按钮应该具有与“下一步”按钮相同的功能。

“我会留在这里并回答”按钮将让用户留在同一页面。

我知道使用 Javascript 是可能的,但我不确定如何实现这个特定任务。

我只知道 Next 按钮的 ID 是“movenextbtn”。

但是,当单击“下一步”按钮并使用确认框时,我将如何检查问题是否未被回答,我将如何进入下一页或留在同一页面。

任何帮助将不胜感激。

提前致谢。

4

2 回答 2

0

这段代码假定您只对表单上具有 id 的按钮的单选按钮感兴趣movenextbtn。您必须将其插入页面中的某个位置。

<script>                                                                        
  // wait for everything to load                                                
  window.addEventListener('load', function() {                                  
    // let's check radio buttons when the next button is clicked   
    var nextButton = document.getElementById('movenextbtn');                    
    var form = nextButton.form;                                                 

    nextButton.addEventListener('click', function(e) {                          
      var radioElements = form.querySelectorAll('input[type="radio"]');         
      var currentRadioName;                                                     
      var seenRadioName;                                                        
      var index;                                                                
      var confirmation;                                                         

      for(index = 0; index < radioElements.length; index += 1) {                
        currentRadioName = radioElements[index].name;                           

        // check if we've already seen this named radio button set              
        if(seenRadioName != currentRadioName) {                                 
          // check that there's a checked radio button for this set of named radio buttons
          if(!form.querySelectorAll('input[type="radio"][name="' + currentRadioName + '"]:checked').length) {
            // didn't answer a question, ask if that's ok                       
            confirmation = confirm("You have missed answering a question.\n\nOK to Continue?\nCancel form submission and answer?");

            if(confirmation) {                                                  
              // the user clicked ok, let's submit the form                     
              return true;                                                      
            }                                                                   
            else {                                                              
              // the user clicked cancel, let's stop the form submission        
              e.preventDefault();                                               
              e.stopPropagation();                                              
              return false;                                                     
            }                                                                   
          }                                                                     

          // remember that we already checked this set of radio buttons         
          seenRadioName = currentRadioName;                                     
        }                                                                       
      }                                                                         
    }, false);                                                                  
  }, false);                                                                    
</script>                                                                       

你可以在这里玩更多:http: //jsbin.com/howuzapi/1/edit

于 2014-08-08T09:47:33.560 回答
0

将此脚本放在数组问题的源代码中:

<script type="text/javascript" charset="utf-8"> 
$(document).ready(function() { 

    // Identify this question
    var thisQuestion = $('#question'+{QID}+'');

    // Listener on the "Next" button
    $('#movenextbtn').click(function(event){
        // Compare number of clicked radios to number of array rows
        if($('input.radio:checked', thisQuestion ).length != $('tr.answers-list',thisQuestion ).length) {
            // Pop up a confirm message
            if(confirm('You have not answered all rows.\n\nAre you sure you want to continue?')) { 
                return true;
            }
            else { 
                return false;
            }
        }
    });
});
</script>
于 2014-08-09T11:02:47.913 回答