简体   繁体   English

单选按钮验证不适用于IE

[英]Radio Button Validation not working on IE

I have following code which validate the questionnaire form and post answers on the next page if all the required answers are entered by the user. 如果用户输入了所有必需的答案,我将使用以下代码来验证问卷调查表并在下一页上发布答案。 This code works perfectly on the Chrome and Other browsers except IE(internet explore). 此代码在IE和Internet浏览器以外的其他浏览器上均能完美运行。 It shows the alert message "Answer All Question" even selecting options all question. 即使选择所有问题选项,它也会显示警告消息“ Answer All Question”。 This thing is happening only in IE.. Can someone tell me why its behaving like this? 这件事仅在IE中发生。有人可以告诉我为什么它会这样吗?

<script type="text/javascript">

//---------------Method for validating the Question whole form --------------//
function checkRadio(name)
{
  var radio = document.forms.myForm[name];
  for (var option in radio)
  {
    if(radio[option].checked)
    { return true; }
  }
  return false;
}

function ValidateQuestions()
{
  if (checkRadio("question1") && checkRadio("question2") && checkRadio("question3") && checkRadio("question4") && checkRadio("question5") && checkRadio("question6") && checkRadio("question7") && checkRadio("question8") && checkRadio("question9") && checkRadio("question10") && checkRadio("question11") && checkRadio("question12") && checkRadio("question13") && checkRadio("question14") && checkRadio("question15") && checkRadio("question16") && checkRadio("question17") && checkRadio("question18") && checkRadio("question19") && checkRadio("question20") ) 
  { return true; }
  else{ return false; }
}

//-----------------------------------------------------------------------------//

jQuery(document).ready(function($) 
{    
    jQuery('#submitFormC').click(function()
    {
     var str = $("#questionnaireForm").serialize();
     var data = {
                 action: 'myajax-submit',
                 s: str,
                 beforeSend: function(){ 
                    $( "#tab" ).empty();
                    $("#tab").append("<img id='busyImg' src='busy.gif'/>");
                    }
                }; 

        if(ValidateQuestions())
        {
        jQuery.post("thankyou.php?t=<?php echo $sid;?>", data,  function(response) { 
        //alert('Got this from the server: ' + response);
        $( "#tab" ).empty().append( response );
        } );
        }
        else { alert("Answer all questions"); }
     return false;   
    });
});
</script>

Try this: Fiddle: http://jsfiddle.net/eNt3c/4/ 试试这个:小提琴: http : //jsfiddle.net/eNt3c/4/

function checkRadio(name)
{
       if($("input[name='"+ name + "']").is(':checked'))
       { return true; }
        alert("Please select " + name);
        return false;
}

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

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