简体   繁体   中英

disable a text area and a button if a cell in datatable is field

I want to disable the text field "ICICI BM/DBM EMP_ID" and "APPROVE" Button in the below code if bank_emp_id is present in database ? Its means if bank_emp_id is present in the database user will not being able to enter any input in the text area and button will remain disabled and if id is not present then the text field and button will remain enable.

Please help as soon as possible.

<?php
include 'includes/header.php';




if(htmlspecialchars(isset($_GET['sid'])))
{
$sid=htmlspecialchars($_GET['sid']);
$sql="SELECT * FROM branchdetail WHERE solID= '{$sid}' ORDER BY id DESC LIMIT 1 ";
$result=mysqli_query($connection,$sql);
while($row=mysqli_fetch_assoc($result)){
?>
<section id="services">
    <div class="container">
        <div class="col-sm-12">
            <table class="table table-bordered">
                <thead>
                    <tr><th align="center" colspan="6">Park Telesolutions Pvt. Ltd.</th></tr>
                    <tr>
                    <th colspan="3">Corporate Office: BlockAQ, Plot No.-12,Sec-V, Salt Lake, Kolkata-700091</th>
                    <th colspan="3">Registered Office: 9/8, Netaji Nagar, Kolkata-700092</th>
                    </tr>
                    <tr>
                    <th colspan="2">Website:- www.parkgroup.co.in</th>
                    <th colspan="2">Phone No.:- (033)6500 2963/64</th>
                    <th colspan="2">Email:- info@parkgroup.co.in</th>
                    </tr>
                    <tr><th align="center" colspan="6">Installation & Commissioning Report</th></tr>
                    <tr>
                    <th colspan="1">Sol ID-<?php echo $row['solID']?></th>
                    <th colspan="2">Branch Name-<?php echo $row['branchName']?></th>
                    <th colspan="3">Branch Address-<?php echo $row['branchAddress']?></th>
                    </tr>
                    <tr>
                        <th colspan="1">SL.NO</th>
                        <th colspan="2">Material Description</th>
                        <th colspan="1">UOM</th>
                        <th colspan="1">BOQ QTY</th>
                        <th colspan="1">Installed QTY</th>
                    </tr>

                    <?php
                    $sql="SELECT * FROM imc WHERE solID= '{$sid}' ORDER BY id DESC LIMIT 1";
                    $result= mysqli_query($connection,$sql);
                    while($row=mysqli_fetch_assoc($result)){
                     ?>
                     <tr>
                        <th colspan="1">1</th>
                        <th colspan="2"><?php echo $row['camera']?></th>
                        <th colspan="1">NOS</th>
                        <th colspan="1"><?php echo $row['cameraqty']?></th>
                        <th colspan="1"><?php echo $row['cameraqty']?></th>
                    </tr>
                    <tr>
                        <th colspan="1">2</th>
                        <th colspan="2"><?php echo $row['dvr']?></th>
                        <th colspan="1">NOS</th>
                        <th colspan="1"><?php echo $row['dvrqty']?></th>
                        <th colspan="1"><?php echo $row['dvrqty']?></th>
                    </tr>
                    <tr>
                        <th colspan="1">3</th>
                        <th colspan="2"><?php echo $row['harddisk']?></th>
                        <th colspan="1">NOS</th>
                        <th colspan="1"><?php echo $row['harddiskqty']?></th>
                        <th colspan="1"><?php echo $row['harddiskqty']?></th>
                    </tr>
                    <tr>
                        <th colspan="1">4</th>
                        <th colspan="2"><?php echo $row['monitor']?></th>
                        <th colspan="1">NOS</th>
                        <th colspan="1"><?php echo $row['monitorqty']?></th>
                        <th colspan="1"><?php echo $row['monitorqty']?></th>
                    </tr>
                    <tr>
                        <th colspan="1">5</th>
                        <th colspan="2"><?php echo $row['smps']?></th>
                        <th colspan="1">NOS</th>
                        <th colspan="1"><?php echo $row['smpsqty']?></th>
                        <th colspan="1"><?php echo $row['smpsqty']?></th>
                    </tr>
                    <tr>
                        <th colspan="1">6</th>
                        <th colspan="2"><?php echo $row['cameracable']?></th>
                        <th colspan="1">Per Mtr.</th>
                        <th colspan="1"><?php echo $row['cameracableqty']?></th>
                        <th colspan="1"><?php echo $row['cameracableqty']?></th>
                    </tr>
                    <tr>
                        <th colspan="1">7</th>
                        <th colspan="2"><?php echo $row['camerapowercable']?></th>
                        <th colspan="1">Per Mtr.</th>
                        <th colspan="1"><?php echo $row['camerapowercableqty']?></th>
                        <th colspan="1"><?php echo $row['camerapowercableqty']?></th>
                    </tr>
                    <tr>
                        <th colspan="1">8</th>
                        <th colspan="2"><?php echo $row['conduitpipe']?></th>
                        <th colspan="1">Per Mtr.</th>
                        <th colspan="1"><?php echo $row['conduitpipeqty']?></th>
                        <th colspan="1"><?php echo $row['conduitpipeqty']?></th>
                    </tr>



                    <tr>

                    <th colspan="4">I&C Report No.- <?php echo $row['POno']?></th>
                    <th colspan="2">DATE- <?php echo $row['date']?></th>
                    </tr>

                    <tr>
                    <th colspan="3">PARK Emp_ID- <?php echo $row['park_emp_id']?></th>
                    <th colspan="3">ICICI BM/DBM Emp_ID- <?php echo $row['bank_emp_id']?></th>

                    </tr>
                  <?php
}}}
                   ?> 
                </thead>
            </table>
        </div>
        </div>
</section>
<div class="col-sm-12">

<form class="" action="" method="post">
    <div class="form-group">
        <label for="comment">ICICI BM/DBM EMP_ID:</label>
        <input type="text" class="form-control" id="bank_emp_id" name="bank_emp_id" required="require" placeholder="Please Enter Your ICICI EMP-ID">
    </div><br>
    <button type="submit" class="btn btn-default" name="submit">Approve</button>
</form>
<div class="col-sm-8 col-sm-offset-2 text-right">
    <h4><a href="home.php?solid=<?php echo $sid;?>">Back</a></h4>
</div>

<br><br><br><br>
<?php   
if(htmlspecialchars(!isset($_POST['submit']))){
        //header('Location:create_bmDbm.php');
    }else{

        $bank_emp_id=htmlspecialchars($_POST['bank_emp_id']);
        $sql="UPDATE imc SET bank_emp_id='{$bank_emp_id}'";
        $sql.=" WHERE solID='{$sid}' ORDER BY id DESC LIMIT 1";

        $result=mysqli_query($connection,$sql);

        if(!$result){
            echo 'ERROR'.mysqli_error($connection);
        }else{

            header('Location:sensor_detail.php?sid='.$sid.'&bank_emp_id='.$bank_emp_id);
        }
    }

?>
</div>
<?php    include 'includes/footer.php'; ?> 

Try to use following code HTML : <input type="text" onkeyup="checkAvailability(this);" class="form-control" id="bank_emp_id" name="bank_emp_id" required="require" placeholder="Please Enter Your ICICI EMP-ID"> <input type="text" onkeyup="checkAvailability(this);" class="form-control" id="bank_emp_id" name="bank_emp_id" required="require" placeholder="Please Enter Your ICICI EMP-ID">

Jquery/Ajax:

<script src="https://code.jquery.com/jquery-2.1.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
function checkAvailability(e) {
var check = $("#bank_emp_id").val();
jQuery.ajax({
url: "check.php",
data:'check='+check,
type: "POST",
success:function(data){
if(data=="Exist"){
$("input").attr('disabled',true);
}else{
$("input").attr('disabled',false);
}
},
error:function (){}
});
}
</script>

The check.php

// include your connection file
if(!empty($_POST['check'])){
$check=$_POST['check'];
$query=mysqli_query($conn,"SELECT bank_emp_id FROM your_table_name WHERE bank_emp_id='$check'");
$numrows=mysqli_num_rows($query);
if($numrows > 0){
echo "Exist";
}else{
echo "";
}
}

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