简体   繁体   中英

COLDFUSION: select one checkbox for td(row) in a table loop

In the code below, I iterate through a table. There are two check-boxes for the desired row. Once the first box is checked, I want to prevent the user from checking the other in that row. If the user checks the second, s/he should be able to check other boxes (options).

 <cfquery name="data" datasource="#dbMarks#"> SELECT helix_date, Helix_Title FROM Helix_Events </cfquery> <div class="container"> <div class="row"> <form action="save.cfm"> <div class="col-sm-12 col-md-8"> <h2>Select Helix Programme</h2> </div> <div class="col-sm-12 col-md-4 mtr mtop"> <select name="" id="" class="btn-markham"> <option value="">Semester 1</option> <option value="">Semester 2</option> </select> <button class="btn-markham" onclick="myFunction()"><span class="fa fa-print"></span>&nbsp;Print</button> <input type="submit" class="btn-markham2" value="Save"> <br></br> </div> <div class="col-md-12"> <table class="table"> <tr> <th>Date</th> <th>Event</th> <th class="mtc">Participation</th> <th class="mtc">Support</th> </tr> <cfoutput query="data" > <tr> <td>#dateformat(helix_date,"dd-mmm-yy")#</td> <td>#helix_title#</td> <td class="mtc"><input type="checkbox" name="check" value="1"> </td> <td class="mtc"><input type="checkbox" name="check2" value="2"></td> </tr> </cfoutput> </table> </div> </div> </form> </div> </div>

Please use this code line . jQuery(this).closest('tr').find('[type=checkbox]').not(this).prop('disabled', true); which make the next checkbox disabled on check of current of checkbox. Same way you can remove the disabled checkbox on uncheck using jQuery(this).closest('tr').find('[type=checkbox]').not(this).prop('disabled', false);

Please check below snippet for more understanding.

 $("input[type='checkbox']").on('change',function(){ if($(this).is(':checked')){ jQuery(this).closest('tr').find('[type=checkbox]').not(this).prop('disabled', true); }else{ jQuery(this).closest('tr').find('[type=checkbox]').not(this).prop('disabled', false); } });
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <cfquery name="data" datasource="#dbMarks#"> SELECT helix_date, Helix_Title FROM Helix_Events </cfquery> <div class="container"> <div class="row"> <form action="save.cfm"> <div class="col-sm-12 col-md-8"> <h2>Select Helix Programme</h2> </div> <div class="col-sm-12 col-md-4 mtr mtop"> <select name="" id="" class="btn-markham"> <option value="">Semester 1</option> <option value="">Semester 2</option> </select> <button class="btn-markham" onclick="myFunction()"><span class="fa fa-print"></span>&nbsp;Print</button> <input type="submit" class="btn-markham2" value="Save"> <br></br> </div> <div class="col-md-12"> <table class="table"> <tr> <th>Date</th> <th>Event</th> <th class="mtc">Participation</th> <th class="mtc">Support</th> </tr> <cfoutput query="data" > <tr> <td>#dateformat(helix_date,"dd-mmm-yy")#</td> <td>#helix_title#</td> <td class="mtc"><input type="checkbox" name="check" value="1"> </td> <td class="mtc"><input type="checkbox" name="check2" value="2"></td> </tr> </cfoutput> </table> </div> </div> </form> </div> </div>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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