简体   繁体   English

如何使用Codeigniter中的Jquery禁用单选按钮的值?

[英]How to get values of radio button if they are disabled using Jquery in Codeigniter?

In Application, i have group of question and answer. 在应用程序中,我有一组问题和答案。 Every question has 3 set of answer that type are radio button.all question and answer in form. 每个问题有3组答案,其类型为单选按钮。所有问题和答案均采用表格形式。 if i answer any question and click on next button then that question's answer will disabled. 如果我回答任何问题并单击下一步按钮,则该问题的答案将被禁用。 Right now i disabled it on next but at the last when i click on submit.then i am getting all values from form submit. 现在我在下一个禁用它,但是最后一次当我单击Submit.then我从form提交获取所有值。

Script Code : 脚本代码:

<script type="text/javascript">
    $('.forward').click(function(event) {
       $('input[type=radio]:checked').each(function(index, el) {
           var title = $(this).attr('name');
            $("input[name="+title+"]:radio").attr('disabled',true);

       });
    });
</script>

In Codeigniter Code : 在Codeigniter代码中:

function insertValues() {
     $answer = $this->input->post();
}

Html Code: HTML代码:

<form method="post" action="http://localhost/demo/insertValues">

<div>
<h3>Question 1 ?</h3>
<input name="1" type="radio" value="111">
<input name="1" type="radio" value="112">
<input name="1" type="radio" value="113">
</div>

<div>
<h3>Question 2 ?</h3>
<input name="2" type="radio" value="121">
<input name="2" type="radio" value="122">
<input name="2" type="radio" value="123">
</div>

<button type="button" name="forward" class="forward">Save &amp; Next</button>


<button type="submit" name="submit" class="submit">See Report</button>
</form>

One possibility is to enable them in a submit event handler 一种可能是在提交事件处理程序中启用它们

$(function(){
    $('form').on('submit', function(){
        $(this).find(':radio').prop('disabled', false);
    });
});
 $('form input[type=radio]').each(function(){
      if($(this).prop('disabled',true) == true)
           alert('My property is disabled'+$(this).val());
 }

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

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