How to check all checkboxes with different names in the same row - javascript

I Have html table as below code, How to check all checkboxes with different names in the same row??
Such as in the row of "Item name 1": if I check the box of "Check all", and then the box of "Date of Start: 2022-04-01" and the box of " Date of End: 2022-04-30" will be auto checked.
<table border="1" cellpadding="10" cellspacing="1" width="100%" class="tblListForm">
<tbody><tr class="listheader">
<script language="JavaScript">
function toggle(source) {
checkboxes = document.getElementsByName('tbid[]');
for(var i=0, n=checkboxes.length;i<n;i++) {
checkboxes[i].checked = source.checked;
}
}
</script>
<td style="width:10%"><input type="checkbox" onclick="toggle(this)">Quantity/Select All</td>
<td style="width:67%"> Item Details </td>
<td style="width:10%; text-align:right;"> Unit Price </td>
<td style="width:13%; text-align:right;"> Sub-total </td>
</tr>
<tr class="evenRow">
<td style="vertical-align:top">
<input type="checkbox" name="tbid[]" value="238"> 1</td>
<td style="vertical-align:top">
Item name 1 <br>
<input type="checkbox" name="item_no[]" value="1"> Check all<input type="checkbox" name="item_date_start[]" value="2022-04-01">Date of Start: 2022-04-01<input type="checkbox" name="item_date_end[]" value="2022-04-30"> Date of End: 2022-04-30</td>
<td style="vertical-align:top; text-align:right;">
105.00</td>
<td style="vertical-align:top; text-align:right;">
105.00</td>
</tr>
<tr class="oddRow">
<td style="vertical-align:top">
<input type="checkbox" name="tbid[]" value="239"> 1</td>
<td style="vertical-align:top">
Item name 2<br>
<input type="checkbox" name="item_no[]" value="17"> Check all<input type="checkbox" name="item_date_start[]" value="2022-05-01">Date of Start: 2022-05-01<input type="checkbox" name="item_date_end[]" value="2022-05-31"> Date of End: 2022-05-31</td>
<td style="vertical-align:top; text-align:right;">
250.00</td>
<td style="vertical-align:top; text-align:right;">
250.00</td>
</tr>
<tr class="listheader">
<td></td>
<td></td>
<td style="vertical-align:top; text-align:right;"> Total (HKD): </td>
<td style="vertical-align:top; text-align:right;"> 355.00</td>
</tr>
</tbody>
</table>
Thank you very much for your sharing & support in advance!

In this example I added a <fieldset> as a (near) parent to the checkboxes. The event listener will look for any change in the form. In the if() statement I determine if it was a "Check all" that changed. If so, all the input elements in the closest fieldset should have the same value.
document.forms.form01.addEventListener('change', e => {
// the field that just changed
let field = e.target;
// somehow determine if the change was
// on a "Check all" field -- here if class name = "checkall"
if (field.className == 'checkall') {
// get the parent fieldset
let fieldset = e.target.closest('fieldset');
// for each element in fieldset
[...fieldset.elements].forEach(input => {
// all should have the same value as "check all"
input.checked = field.checked;
});
}
});
<form name="form01">
<table>
<tr>
<td style="vertical-align:top">
<fieldset>
<label><input type="checkbox" name="item_no[]" class="checkall" value="1">Check all</label>
<label><input type="checkbox" name="item_date_start[]" value="2022-04-01">Date of Start: 2022-04-01</label>
<label><input type="checkbox" name="item_date_end[]" value="2022-04-30"> Date of End: 2022-04-30</label>
</fieldset>
</td>
</tr>
</table>
</form>

I find a similar answer from the web as below, but how to remove checkbox if click Uncheck, need to rewrite the javascript.
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script
type="text/javascript"
src="//code.jquery.com/jquery-1.9.1.js"
></script>
</head>
<body>
<div id="div1">
<input type="button" id="btnDiv1" class="select-all" value="Check / Uncheck" />
<input type="checkbox" class="check" />Mark
<input type="checkbox" class="check" />Frank</div>
<div id="div2">
<input type="button" id="btnDiv2" class="select-all" value="Check / Uncheck" />
<input type="checkbox" class="check" />John
<input type="checkbox" class="check" />Travis
<input type="checkbox" class="check" />Matt</div>
<div id="div3">
<input type="button" id="btnDiv3" class="select-all" value="Check / Uncheck" />
<input type="checkbox" class="check" />Lee
<input type="checkbox" class="check" />Charles</div>
<script type="text/javascript">
$('.select-all').on('click', function ()
{
$(this).nextAll('.check').prop('checked', true);
});
</script>
</body>
</html>

Related

jQuery set value of each previous sibling of each ticked checkbox upon submit

I have been searching solutions for this and found that the most effective way is through a hacky workaround like this, but none of them has posted a working way to catching every tick and untick box for a dynamic input row using a lot of checkbox arrays.
I looked around and saw a script way -- let hidden inputs be the POST source and change value according to their adjacent checkbox upon submit. However the jquery doesn't seem to work -- it always submits a value of 0 (whatever the value attribute inside hidden inputs.
$(document).ready(function() {
$('#frm').submit(function() {
$('input[type="checkbox"]:checked').prev('.checkboxHandler').val(1);
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<input type="hidden" class="checkboxHandler" name="isHeadOfFamily[]" value="0">
<td><input type="checkbox"></td>
<input type="hidden" class="checkboxHandler" name="isEmployed[]" value="0">
<td><input type="checkbox"></td>
<! and so on-->
Your code works
I will delete this answer once we have discussed it
I have changed hidden to text and added preventDefault to show it works
$(document).ready(function() {
$('#frm').on("submit",function(e) {
e.preventDefault(); //while testing
$('input[type="checkbox"]:checked').prev('.checkboxHandler').val(1);
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<form id="frm">
<input type="text" class="checkboxHandler" name="isHeadOfFamily[]" value="0">
<td><input type="checkbox"></td>
<input type="text" class="checkboxHandler" name="isEmployed[]" value="0">
<td><input type="checkbox"></td>
<! and so on-->
<input type="submit"/>
</form>
Consider the following example.
$(function() {
function getTableData(table) {
var results = [];
$("tbody > tr", table).each(function(i, row) {
results.push({
id: $(row).data("uid"),
isHeadofHousehold: $("input", row).eq(0).prop("checked"),
isEmployed: $("input", row).eq(1).prop("checked")
});
});
return results;
}
$('#frm').on("submit", function(e) {
e.preventDefault();
var formData = getTableData($("#myTable"));
console.log(formData);
});
});
.checkbox {
text-align: center;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<form id="frm">
<table id="myTable">
<thead>
<tr>
<th>Name</th>
<th>Head of Household</th>
<th>Employed</th>
</tr>
</thead>
<tbody>
<tr data-uid="1001">
<td>Homer Simpson</td>
<td class="checkbox"><input type="checkbox" name="isHeadOfFamily[]" checked></td>
<td class="checkbox"><input type="checkbox" name="isEmployed[]" checked></td>
</tr>
<tr data-uid="1002">
<td>Marge Simpson</td>
<td class="checkbox"><input type="checkbox" name="isHeadOfFamily[]"></td>
<td class="checkbox"><input type="checkbox" name="isEmployed[]"></td>
</tr>
</tbody>
</table>
<input type="submit" value="Save" />
</form>
You now have:
[
{
"id": 1001,
"isHeadofHousehold": true,
"isEmployed": true
},
{
"id": 1002,
"isHeadofHousehold": false,
"isEmployed": false
}
]
You can then use AJAX to POST this data back to PHP so the changes can be saved to SQL. As mentioned, you can switch them to 1 and 0 respectively if you choose.
Update
Returning to OP's desired method, consider the following.
$(function() {
$("#frm").on("change", "input[type='checkbox']", function(event) {
$(this).prev(".checkboxHandler").val($(this).prop("checked") ? 1 : 0);
});
});
.checkbox {
text-align: center;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<form id="frm">
<table id="myTable">
<thead>
<tr>
<th>Name</th>
<th>Head of Household</th>
<th>Employed</th>
</tr>
</thead>
<tbody>
<tr data-uid="1001">
<td>Homer Simpson</td>
<td class="checkbox">
<input type="hidden" class="checkboxHandler" name="isHeadOfFamily[]" value="1" />
<input type="checkbox" checked />
</td>
<td class="checkbox">
<input type="hidden" class="checkboxHandler" name="isEmployed[]" value="1" />
<input type="checkbox" checked />
</td>
</tr>
<tr data-uid="1002">
<td>Marge Simpson</td>
<td class="checkbox">
<input type="hidden" class="checkboxHandler" name="isHeadOfFamily[]" value="0" />
<input type="checkbox" />
</td>
<td class="checkbox">
<input type="hidden" class="checkboxHandler" name="isEmployed[]" value="0" />
<input type="checkbox" />
</td>
</tr>
</tbody>
</table>
<input type="submit" value="Save" />
</form>
This updates the hidden text box value when a User makes a change.
If you are insistent on using the original code, use the following:
$('input[type="checkbox"]:checked').prevAll('.checkboxHandler').val(1);
I strongly advise not using this, as it's a one way logic and if the User unchecks a box before the form is submitted, the change will not be captured.
Update 2
Based on the Top rated answer here, you could also do this:
<td>
<input type="hidden" name="isHeadOfFamily[]" value="0">
<input type="checkbox" name="isHeadOfFamily[]" value="1">
</td>
<td>
<input type="hidden" name="isEmployed[]" value="0">
<input type="checkbox" name="isEmployed[]" value="1">
</td>
The only caveat is that if the User checks a box, both values would get sent. So as suggested, disable the hidden upon submit if unchecked.
$("#frm").submit(function(){
$('input[type="checkbox"]:checked').prevAll().prop("disabled", true);
});

Show/hide elements with checkbox check/unchek

I am trying to show and hide tr of table with checkbox check and uncheck. I tried the following script not working for me.
$('.checks').on('ifChecked', function(event) {
var checked = $(this).val();
if (checked == 1) {
$('.vegetables').show();
}
if (checked == 2) {
$('.fruits').show();
}
});
.hidden {
display: none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="form-group">
<label class="checkbox-inline">
<input type="checkbox" class="checks" value="1">vegetables
</label>
<label class="checkbox-inline">
<input type="checkbox" class="checks" value="2">Fruits
</label>
</div>
<table>
<tbody>
<tr class="vegetables hidden">
<td colspan="2">
<h2>Vegetablese:</h2>
</td>
</tr>
<tr class="vegetables hidden">
<td>
<label>Vegetables:</label>
<input type="text">
</td>
</tr>
<tr class="fruits hidden">
<td colspan="2">
<h2>Fruits:</h2>
</td>
</tr>
<tr class="fruits hidden">
<td>
<label>Fuits:</label>
<input type="text">
</td>
</tr>
</tbody>
</table>
Here's what you need to do:
Change ifChecked with onchange. There's no event like ifChecked.
Use toggle based on the state of the checkbox.
Check for $(this).checked to find the state. This will return true or false.
$('.checks').on('change', function(event) {
var checked = $(this).val();
if (checked == 1) {
$('.vegetables').toggle($(this).checked);
}
if (checked == 2) {
$('.fruits').toggle($(this).checked);
}
});
.hidden {
display: none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="form-group">
<label class="checkbox-inline">
<input type="checkbox" class="checks" value="1" /> vegetables
</label>
<label class="checkbox-inline">
<input type="checkbox" class="checks" value="2" /> Fruits
</label>
</div>
<table>
<tbody>
<tr class="vegetables hidden">
<td colspan="2">
<h2>Vegetablese:</h2>
</td>
</tr>
<tr class="vegetables hidden">
<td>
<label>Vegetables:</label>
<input type="text">
</td>
</tr>
<tr class="fruits hidden">
<td colspan="2">
<h2>Fruits:</h2>
</td>
</tr>
<tr class="fruits hidden">
<td>
<label>Fuits:</label>
<input type="text">
</td>
</tr>
</tbody>
</table>
Theres a couple of issues in your logic. Firstly ifChecked is not a valid event. Use change instead. Secondly the logic doesn't work to hide elements. To do that you'd need to loop through all checkboxes and determine their state in order to show/hide the content underneath.
The simplest and most extensible way to achieve what you require is to use a data attribute to specify which element should be toggled when the checkbox is updated. Then you can simply hide/show each element in the set. Try this:
let $checks = $('.checks').on('change', () => $checks.each((i, el) => $(el.dataset.target).toggle(el.checked)));
.hidden {
display: none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="form-group">
<label class="checkbox-inline">
<input type="checkbox" class="checks" value="1" data-target=".vegetables">vegetables
</label>
<label class="checkbox-inline">
<input type="checkbox" class="checks" value="2" data-target=".fruits">Fruits
</label>
</div>
<table>
<tbody>
<tr class="vegetables hidden">
<td colspan="2">
<h2>Vegetablese:</h2>
</td>
</tr>
<tr class="vegetables hidden">
<td>
<label>Vegetables:</label>
<input type="text">
</td>
</tr>
<tr class="fruits hidden">
<td colspan="2">
<h2>Fruits:</h2>
</td>
</tr>
<tr class="fruits hidden">
<td>
<label>Fuits:</label>
<input type="text">
</td>
</tr>
</tbody>
</table>

jQuery Uncheck other checkbox on one checked from same row

HelloI would like to tell you that I know there are lots of solved example on stack overflow regarding the same issues.But My query is bit complex and make me sick.I have large number of table that consist of 10 rows and 9 columns.
All I want is when user check the NONE checkbox for STROKE, other checkbox unchecked from the same row.I have to do it for every row.
and if Other checkbox checked (user can check multiple either PARENT,UNCLE,OTHERS,etc.),NONE checkbox will unchecked.
Incase of query ask me.
I am trying from last 2 days for the same, but can successed in it.
Please Help me
Thanks in advance.
HEART NONE PARENT UNCLE/AUNT GRANDPARENT OTHERS
===============================================================
STROKE
ATTACK
B.P.
BLOOD NONE PARENT UNCLE/AUNT GRANDPARENT OTHERS
===============================================================
ANEMIA
IMMUNE
LUKEMIA
Use the same class for same row.In each row you can give different class name and do further same.I given you one row the sample.
$(function(){
$("input[type='checkbox']").click(function(){
if($(this).prop('checked') == true && $(this).attr('class')=='none'){
$(this).closest("tr").find("input[type='checkbox']").each(function(){
$(this).prop('checked', false);
});
$(this).prop('checked',true);
}
else{
$(this).closest("tr").find("input[type='checkbox']").each(function(){
$(this).closest('.none').prop('checked',false);
});
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table border='0'>
<tr><th>HEART</th><th>NONE</th><th>PARENT</th><th>UNCLE/AUNT</th><th>GRANDPARENT</th><th>OTHERS</th><tr>
<tr><td>STROKE</td><td><input type='checkbox' class='none'></td><td><input type='checkbox' class='stroke'></td><td><input type='checkbox' class='stroke'></td><td><input type='checkbox' class='stroke'></td><td><input type='checkbox' class='stroke'></td></tr>
<tr><td>ATTACK</td><td><input type='checkbox' class='none'></td><td><input type='checkbox' class='attack'></td><td><input type='checkbox' class='attack'></td><td><input type='checkbox' class='attack'></td><td><input type='checkbox' class='attack'></td></tr>
</table>
$(".checkAll").on("change",function(){
if($(this).is(":checked"))
$(this).closest("tr").find(".check").prop('checked',true);
else
$(this).closest("tr").find(".check").prop('checked',false);
});
td:first-child{
background-color:yellow
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table >
<tbody>
<tr>
<td><input type="checkbox" class="checkAll" />check All1</td>
<td><input type="checkbox" class="check" />check 1</td>
<td><input type="checkbox" class="check" />check 1</td>
</tr>
<tr>
<td><input type="checkbox" class="checkAll" />check All2</td>
<td><input type="checkbox" class="check" />check 2</td>
<td><input type="checkbox" class="check"/>check 2</td>
</tr>
</tbody>
</table>
My solution was to uncheck all the closest checkboxes and recheck the clicked one. (Works with tables)
<script>
$(document).ready(function() {
$(':checkbox').on('change', function() {
$(this).closest('tr').find(':checkbox').prop('checked', false);
$(this).prop('checked', true);
});
});
</script>
This will work ;)
<div>
<input type="checkbox" name="none" value="" id="none">
<input type="checkbox" name="parent" value="" id="parent" class="otherThanNone">
<input type="checkbox" name="uncle" value="" id="uncle" class="otherThanNone">
<input type="checkbox" name="aunt" value="" id="aunt" class="otherThanNone">
</div>
<script>
$(document).ready(function(){
if($('#none').prop('checked')==false){
$('#none').click(function(){
for(var i=0; i<3; ++i){
if($('.otherThanNone').eq(i).prop('checked')==true){
$('.otherThanNone').eq(i).prop('checked', false);
}
}
});
}
$('#parent').click(function(){
$('#none').prop('checked', false);
console.log('a');
});
});
</script>
<!DOCTYPE html>
<html>
<head>
<title>Checkbox selection</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
</head>
<body>
<table>
<tr>
<th>HEART</th>
<th>NONE</th>
<th>PARENT</th>
<th>UNCLE/AUNT</th>
<th>GRANDPARENT</th>
<th>OTHERS</th>
</tr>
<tr>
<td>STROKE</td>
<td class="strokeTD"><input type="checkbox" class="Strokeclass" name="heart"></td>
<td class="strokeTD"><input type="checkbox" class="Strokeclass" name="none"></td>
<td class="strokeTD"><input type="checkbox" class="Strokeclass" name="parent"></td>
<td class="strokeTD"><input type="checkbox" class="Strokeclass" name="uncle"></td>
<td class="strokeTD"><input type="checkbox" class="Strokeclass" name="grandparent"></td>
<td class="strokeTD"><input type="checkbox" class="Strokeclass" name="others"></td>
</tr>
<tr>
<td>ATTACK</td>
<td class="attackTD"><input type="checkbox" class="Strokeclass" name="heart"></td>
<td class="attackTD"><input type="checkbox" class="Strokeclass" name="none"></td>
<td class="attackTD"><input type="checkbox" class="Strokeclass" name="parent"></td>
<td class="attackTD"><input type="checkbox" class="Strokeclass" name="uncle"></td>
<td class="attackTD"><input type="checkbox" class="Strokeclass" name="grandparent"></td>
<td class="attackTD"><input type="checkbox" class="Strokeclass" name="others"></td>
</tr>
<tr>
<td>B.P.</td>
<td class="bpTD"><input type="checkbox" class="Strokeclass" name="heart"></td>
<td class="bpTD"><input type="checkbox" class="Strokeclass" name="none"></td>
<td class="bpTD"><input type="checkbox" class="Strokeclass" name="parent"></td>
<td class="bpTD"><input type="checkbox" class="Strokeclass" name="uncle"></td>
<td class="bpTD"><input type="checkbox" class="Strokeclass" name="grandparent"></td>
<td class="bpTD"><input type="checkbox" class="Strokeclass" name="others"></td>
</tr>
</table>
</body>
<script type="text/javascript">
$(document).on('click','.Strokeclass',function(){
var js_class = $(this).parent().attr('class');
var js_slected = $(this).attr('name');
if(js_slected == 'none')
{
$( '.'+js_class ).each(function( ) {
if($(this).children().attr('name') != 'none')
{$(this).children().prop('checked', false);}
});
}
else if(js_slected == 'others')
{
$( '.'+js_class ).each(function( ) {
if($(this).children().attr('name') == 'none')
{$(this).children().prop('checked', false);}
});
}
});
</script>
</html>
$(".checkAll").on("change",function(){
if($(this).is(":checked"))
$(this).closest("tr").find(".check").prop('checked',true);
else
$(this).closest("tr").find(".check").prop('checked',false);
});
td:first-child{
background-color:yellow
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table >
<tbody>
<tr>
<td><input type="checkbox" class="checkAll" />check All1</td>
<td><input type="checkbox" class="check" />check 1</td>
<td><input type="checkbox" class="check" />check 1</td>
</tr>
<tr>
<td><input type="checkbox" class="checkAll" />check All2</td>
<td><input type="checkbox" class="check" />check 2</td>
<td><input type="checkbox" class="check"/>check 2</td>
</tr>
</tbody>
</table>

how to make checkbox unchecked when other checkbox is checked in angular

I have a table where it shows the list of deleted items.
User can either recover the item or delete permanently. i need help in making only one checkbox is checked in a table row and uncheck other checkbox when user try to check both. Also when checkbox is checked in table header, it should select all the checkboxes in that td.
$(function() {
$('input.example').on('change', function() {
$("tr").closest('input.example').not(this).prop('checked', false);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<div ng-app>
<table>
<th>
<label>
<input type="checkbox" class="example" />Recover</label>
<label>
<input type="checkbox" class="example" />Delete</label>
</th>
<tr>
<td>
<input type="checkbox" class="example" />
</td>
<td>
<input type="checkbox" class="example" />
</td>
</tr>
<tr>
<td>
<input type="checkbox" class="example" />
</td>
<td>
<input type="checkbox" class="example" />
</td>
</tr>
</table>
</div>
This is exactly the scenario where you should be using radio inputs, not checkboxes, as you get this behaviour by default without the need for any JS code. All you have to do is group the required input elements by their name attribute. Try this:
<div ng-app>
<table>
<th>
<label><input type="radio" name="foo1" />Recover</label>
</th>
<th>
<label><input type="radio" name="foo1" />Delete</label>
</th>
<tr>
<td>
<input type="radio" name="foo2" />
</td>
<td>
<input type="radio" name="foo2" />
</td>
</tr>
<tr>
<td>
<input type="radio" name="foo3" />
</td>
<td>
<input type="radio" name="foo3" />
</td>
</tr>
</table>
</div>
i figured it out myself without using radio buttons and its working fine.
JS code
$scope.uncheckPermDelete = function (ip) {
if($("input[name=perm_delete_check_"+ ip.id +"]").prop('checked', true)) {
$("input[name=perm_delete_check_"+ ip.id +"]").prop('checked', false);
ip.perm_delete = 0;
}
};
$scope.uncheckRecover= function (ip) {
if($("input[name=recover_check_"+ ip.id +"]").prop('checked', true)) {
$("input[name=recover_check_"+ ip.id +"]").prop('checked', false);
ip.deleted = 1;
}
};
HTML code
<td ><input class="recover_check" name="recover_check_{{ip.id}}" ng-change="uncheckPermDelete(ip)" type="checkbox" ng-model="ip.deleted" ng-true-value="0" ng-false-value="1" /></td>

How to disable Checkbox after checking another checkbox in array

How to disable the checkbox with the name="check_no[]" after checking the checkbox name="check_yes[]"?
<tr>
<td colspan="" width="6%">
<center>
<input type="checkbox" name="check_yes[]" value="yes">
</center>
</td>
<td colspan="" width="6%">
<center>
<input type="checkbox" name="check_no[]" value="no">
</center>
</td>
</tr>
You can use a combination of closest() and find() to get the neighbouring child checkbox and then disable it using prop(), something like this:
$('table :checkbox').change(function() {
$(this).closest('tr').find(':checkbox').not(this).prop('disabled', true);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr>
<td colspan="" width="6%">
<center>
<input type="checkbox" name="check_yes[]" value="yes">
</center>
</td>
<td colspan="" width="6%">
<center>
<input type="checkbox" name="check_no[]" value="no">
</center>
</td>
</tr>
</table>
$("table [name='check_yes[]']").change(function() {
if($(this).is(":checked")) {
$("[name='check_no[]']").prop('disabled', true);
}
});
This listens for any check_yes[] check and disables all other check_no[] on the page if it was checked
function enab1() {
document.getElementById("check_no").disabled = true;
}
function enab2() {
document.getElementById("check_yes").disabled = true;
}
in your html code
<input type="checkbox" name="check_yes[]" value="yes" onclick="enab1()">
<input type="checkbox" name="check_no[]" value="yes" onclick="enab2()">
Hope this will works

Categories

Resources