Reputation: 21
I have 4 radiobutton r1,r2,r3,r4. And a date input "tanggal".
in my table i have data in row tanggal 11/15/2018, 11/15/2018, 11/15/2018 11/15/2018
row waktu09.00, 09.20, 09.40, and 10.00
with this query I just can disable one radio button r1
when I choose a date 11/15/2018
with value in my database
<script type="text/javascript">
$(document).ready(function(){
$('#tanggal').change(function(){
var tanggalfromfield = $('#tanggal').val();
$.ajax({ // Memulai ajax
method: "POST",
url: "ajaxtanggal.php",
data: {tanggal: tanggalfromfield}
})
.done(function(hasilajax) {
$('#nama').val(hasilajax);
var tam=hasilajax;
if(tam=='09.00WIB'){
document.getElementById("r1").disabled = true;
}
});
})
});
</script>
when i try to use if else statement nothing change and it's not work.
<script type="text/javascript">
$(document).ready(function(){
$('#tanggal').change(function(){
var tanggalfromfield = $('#tanggal').val(); // AMBIL isi dari fiel NPM masukkan variabel 'npmfromfield'
$.ajax({ // Memulai ajax
method: "POST",
url: "ajaxtanggal.php", // file PHP yang akan merespon ajax
data: {tanggal: tanggalfromfield} // data POST yang akan dikirim
})
.done(function(hasilajax) {
$('#nama').val(hasilajax);
var tam=hasilajax;
if(tam=='09.00WIB'){
document.getElementById("r1").disabled = true;
}else if(tam=='09.20WIB'){
document.getElementById("r2").disabled = true;
}else if(tam=='09.40WIB'){
document.getElementById("r3").disabled = true;
}
});
})
});
</script>
How to disable r2,r3,r4 when I choose date 11/15/2018
?
Upvotes: 0
Views: 204
Reputation: 562
You need to make standart debugging actions:
1) check tam=='09.00WIB - is this still works? According to code - must be.
2) use
$('#nama').val(hasilajax);
var tam=hasilajax;
console.log('tam:'); console.log(tam);
to see real value of tam. It can be surprisingly not what you expect.
3) add message in various statement to check if it is goes here:
if(tam=='09.00WIB'){
document.getElementById("r1").disabled = true;
console.log('r1 - worked');
}else if(tam=='09.20WIB'){
document.getElementById("r2").disabled = true;
console.log('r2 - worked');
}else if(tam=='09.40WIB'){
document.getElementById("r3").disabled = true;
console.log('r3 - worked');
} else {
console.log('nothing of this');
}
Only then you can understand where is error. Probably not in "if else if"
Upvotes: 1