-1

Hi i have two condition on checkbox value so while check

i)if user click "no record " other checkbox had to disable  or
ii)it have to alert only no record have to select like that or
iii) while click of no record other selection have not allowed to check

my code:

<tr class='tablecolor-L-TD' id="+sno+">" +
              "<td class='lc_sno_1' ><center> "+sno+"</center></td>"+
              "<td class='lc_survey_1' ><center> "+v.surveyNo+"</center></td>" +
              "<td class='lc_subdiv_1' ><center> "+v.subdivNo+"</center></td>" +
              "<td class='lc_ExtAres_1' ><center> "+v.ext_ares+"</center></td>" +
              "<td class='lc_ownerdetail_1' ><center> "+cnt_OwnrName+"</center></td>"+val+"" +
              "<div id='td_select' style='display: block'>" +
              "<td class='selectall'><center>" +
              "<input type = 'checkbox'  class='chkNumber' value='"+JSON.stringify(v)+"' id = check"+sno+" " +
              " name=check"+sno+" onClick='addSave(this); ;' /></center></td>"

for example:

<input id="check1" class="chkNumber" type="checkbox" onclick="addSave(this); ;" name="check1" value="{"patta":275,"authorityno":1,"villageCode":"057","ownersChitta":}"

<input id="check2" class="chkNumber" type="checkbox" onclick="addSave(this); ;" name="check2" value="{ "flag": "No records"}"

Am newbie how can i check ???

user3607180
  • 185
  • 2
  • 5
  • 14

2 Answers2

1

Try this : bind change event to the 'No Record' checkbox and disabled other checkbox if it is checked or enable when not checked. use .prop() to make disabled / enabled checkbox

$(function(){
  $('#check2').change(function(){
    $('.chkNumber').not(this).prop('disabled',this.checked);
  });
});

EDIT - As OP said, id would not be same every time but value of 'No Record' checkbox will be same. Below is my updated solution

$(function(){
      $('.chkNumber').change(function(){
        var value = $(this).val();
        if(value == '{ "flag": "No records"}')
          $('.chkNumber').not(this).prop('disabled',this.checked);
      });
 });
Bhushan Kawadkar
  • 28,279
  • 5
  • 35
  • 57
  • 1
    Use `.prop()` instead `.attr()` – Satpal Sep 23 '14 at 05:49
  • @Satpal, thanks ... I have updated my answer as per your suggestion. But would like to know why to use `.prop()` as it introduced in version 1.6 is the only reason or is there some other reason to follow it? If you can share a link or post some details about it, would be helpful to me. Thanks :) – Bhushan Kawadkar Sep 23 '14 at 06:00
  • See [.prop() vs .attr()](http://stackoverflow.com/questions/5874652/prop-vs-attr) – Satpal Sep 23 '14 at 06:04
  • @Satpal, thank you very much for sharing this link and clearing my doubts :) – Bhushan Kawadkar Sep 23 '14 at 06:22
  • $('#check2') it not constant i can have many row so at the time it had change but the value wil be same so according to value only we need to restrict the checkbox – user3607180 Sep 23 '14 at 06:33
0

Try this

$(".chkNumber").change(function() {
  var self = this;
  $(".chkNumber").prop('disabled', true);
  $(this).removeAttr('disabled');
});