Reputation: 924
I've coded table creation PHP which create a table using data from a mysql table called job_list. Each row of the table have a button which is used by the user to select the job.
My problem is here I want to disable just one button out of all the buttons. I tried using a single class which disabled all of them. Then I came across another solution here which is what I want but the problem is, every time I've to click twice for the first time when I click the button in order for the code to work. After the initial click code starts to work as intended.
This is my PHP + HTML code
<div class="limiter">
<div class="container-table100">
<div class="wrap-table100">
<div class="table">
<div class="row header">
<div class="cell topLeft">
Customer Name
</div>
<div class="cell">
Target
</div>
<div class="cell">
File Type
</div>
<div class="cell">
Job Comment
</div>
<div class="cell">
Cust. ID
</div>
<div class="cell topRight">
Select Job
</div>
</div>
<?php while ($getJobsRow = $getJobs -> fetch(PDO::FETCH_ASSOC)){ ?>
<?php $loopCount++; //Count the loop run through time ?>
<div class="row">
<div class="cell left <?php if ($numOfRows == $loopCount){ ?>bottomLeft<?php } //Set the CSS class if the loop is at the last row ?> " data-title="Full Name">
<?php echo $getJobsRow['customer_name']; ?>
</div>
<div class="cell" data-title="Age">
<?php echo $getJobsRow['Mal_Name']; ?>
</div>
<div class="cell" data-title="Job Title">
<?php echo $getJobsRow['FileExt']; ?>
</div>
<div class="cell" data-title="Location">
<?php echo $getJobsRow['Job_Comment']; ?>
</div>
<div class="cell" data-title="Location">
<?php echo $getJobsRow['customer_id']; ?>
</div>
<div class="cell right <?php if ($numOfRows == $loopCount){ ?>bottomRight<?php } ?> " data-title="Location">
<button id="selBtnId_<?php echo $getJobsRow['jId']; ?>" class="selJobBtn w3-btn w3-blue-dark w3-round-medium w3-ripple" data-jid="<?php echo $getJobsRow['jId']; ?>">Select</button>
</div>
</div>
<?php } ?>
</div>
</div>
</div>
</div>
My JQuery,
$(document).ready(function () {
$('.selJobBtn').on('click', function () {
$.ajax({
url: '../Functions/OpenjobLister_Function.php',
type: 'get',
data: {
'jid':$(this).data('jid'),
'uid':$('#uId').val()
},
dataType:'text',
complete:function(data){
if(data.responseText !== "1"){
alert("Data not added");
}else{
disableSelBtn();
}
}
});
});
});
function disableSelBtn() {
const $selBtns = $("button[id*='selBtnId_']");
$selBtns.on('click', function () {
$(this).prop('disabled', true);
})
}
I use the AJAX to send and receive data. I only want to disable the button when the data submission is successful. So can some show me how can I just do it in one click with out having to click twice when using for the first time. If there a better way of doing this please show me.
Upvotes: 0
Views: 143
Reputation: 151
$(document).ready(function () {
$('.selJobBtn').on('click', function () {
var thisButton = this;
$.ajax({
url: '../Functions/OpenjobLister_Function.php',
type: 'get',
data: {
'jid':$(this).data('jid'),
'uid':$('#uId').val()
},
dataType:'text',
complete:function(data){
if(data.responseText !== "1"){
alert("Data not added");
}else{
$(thisButton).prop('disabled', true);
//disableSelBtn();
}
}
});
});
});
Upvotes: 1