简体   繁体   中英

How to disable another checkbox when one checkbox has been ticked?(renew)

to make my question before clearly

use sql server 2008 enterprise as database server check my code

table view

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<form method="post" name="form" id="checkForm" action="update.php">

<?php
$aksi="aksi_view.php";
switch($_GET[act]){
  // Tampil User
  default:

    echo "
    <table>
    <tr><th>Ap</th><th>Ccl</th><th>No</th><th>Budg</th><th>Dept</th><th>ItemID</th><th>Item Name</th><th>Qnty</th><th>UOM</th><th>Curr.</th><th>Rate</th><th>Unit Price</th>
    <th>Total</th><th>Total-IDR</th></tr>";

    $p      = new Paging;
    $batas  = 20;
    $posisi = $p->cariPosisi($batas);

    $counter = 1;

    $sql = "SELECT TOP 20 BudgetCategoryID,DeptAbbr, BudgetCategoryAbbr, ItemID, Status,
                            QntyDept, Qnty, CurrencyID, UnitPrice, ExchangeRateIDR, Remark,Proposal,
                            DeptApprovalRemark, M2ApprovalBy, M2ApprovalRemark, ItemName, PurchaseUOMName,
                            DecimalInQnty,(Qnty*UnitPrice) as Total, TotalIDR, CompanyDeptStock, CompanyDeptID, OutstandingNPBB
                            FROM vwBudgetApproval
                            WHERE (M2ApprovalBy IS NOT NULL OR (M2ApprovalBy IS NULL AND  Status =1)) AND 
                            CompletedInd = 1 AND DeptApprovalBy IS NOT NULL 
                            ORDER BY BudgetCategoryID, ItemID";
    $tampil = mssql_query($sql) ;

$no = $posisi+1;

while($r=mssql_fetch_array($tampil)){
  // echo"$no=2 '-'"; 
   //echo"$r[ItemID]";
      $ExchangeRateIDR = number_format($r['ExchangeRateIDR'],2,',','.');
    $unitprice = number_format($r['UnitPrice'],2,',','.'); 
    $total = number_format($r['Total'],2,',','.');
    $totalidr = number_format($r['TotalIDR'],2,',','.');


    $warnaGenap = "#66CCFF";   // warna abu-abu
    $warnaGanjil = "#FFFFFF";  // warna putih

if ($counter % 2 == 0) $warna = $warnaGenap;
else $warna = $warnaGanjil;


echo "<tr bgcolor='".$warna."'>            


 <td><input type= 'checkbox' name='approve".$no."' id='approve'   value='".$r['ItemID']."' onclick='onClickFn()'></td>
                    <td><input type= 'checkbox' name='cancel".$no."' id='cancel'   value='".$r['ItemID']."' onclick='onClickFn()'></td> 
                    <td>$no</td>
                    <td>$r[BudgetCategoryAbbr]</td>
                    <td>$r[DeptAbbr]</td>
                    <td>$r[ItemID]</td>
                    <td>$r[ItemName]</td>
                    <td>$r[Qnty]</td>
                    <td>$r[PurchaseUOMName]</td>
                    <td>$r[CurrencyID]</td>
                    <td>$r[ExchangeRateIDR]</td>
                    <td>$unitprice </td>
                    <td>$total</td>
                    <td>Rp $totalidr</td>";             
          $no++;
          $counter++;

        }
    echo "</table>";
?>

show of the page

图片

now i want the user when checked one checkboxe the other checkbox disable i use the java script for function. here my code

<script type="text/javascript">
function onClickFn(){
$("approve").click(function(){
    if ($(this).prop("checked"))
    {
        $("cancel").prop("checked",false);
    }
});

$("cancel").click(function(){
    if ($(this).prop("checked"))
    {
        $("approve").prop("checked",false);
    }
})
};
</script>

but that function does not work.

1. First of all you have given same id to all <TD>.
2. You haven't used proper id reference in your javascript.
3. Use radio button instead.

jQuery:

$('table').on('click', 'input:checkbox', function() {
    $(this)
    .parents('tr')
    .find('input:checkbox:not(:checked)')
    .attr('disabled', $(this).is(':checked'));
});

http://jsfiddle.net/samliew/ERZge/

But, you really should be using radio buttons instead, unless of course, you want the user to be able to uncheck a checked box.

why don't you just use radio buttons? That seems like a better option. Also if you want the radio buttons disabled this is what the jQuery will look like: jQuery("input:radio").attr('disabled',true);

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