Postingan lainnya
Input multiple data pada checkbox menggunakan ajax
saya mengalami kesulitan dalama menginput multiple data pada checkbox dengan menggunakan ajax dengan data yang ada pada checkbox tidak masuk ke database tapi inputan selain checkbox masuk dan di record pada klom checkbox tertulis "undefined"
<div class="col-md-12 col-sm-12 col-xs-12">
<label class="control-label">Penyakit Yang Diderita: </label>
<div class="checkbox-inline">
<label class="form-check-label">
<input type="checkbox" class="get_value" value="Paru" class="form-check-input">Paru
</label>
</div>
<div class="checkbox-inline">
<label class="checkbox-label">
<input type="checkbox" class="get_value" value="DM" class="form-check-input">DM
</label>
</div>
<div class="checkbox-inline">
<label class="form-check-label">
<input type="checkbox" class="get_value" value="jantung" class="form-check-input">Jantung
</label>
</div>
<div class="checkbox-inline">
<label class="form-check-label">
<input type="checkbox" class="get_value" value="epilepsi" class="form-check-input" >Epilepsi
</label>
</div>
<div class="checkbox-inline">
<label class="form-check-label">
<input type="checkbox" class="get_value" value="hati" class="form-check-input">Hati
</label>
</div>
<div class="checkbox-inline">
<label class="form-check-label">
<input type="checkbox" class="get_value" value="psikosis" class="form-check-input">Psikosis
</label>
</div>
<div class="checkbox-inline">
<label class="form-check-label">
<input type="checkbox" class="get_value" value="ginjal" class="form-check-input">Ginjal
</label>
</div>
<div class="checkbox-inline">
<label class="form-check-label">
<input type="checkbox" class="get_value" value="malaria" class="form-check-input" >Malaria
</label>
</div>
</div>
<div class="col-md-12 col-sm-12 col-xs-12">
<label>Riwayat Penyakit Keluarga: </label>
<div class="checkbox-inline">
<label class="form-check-label">
<input type="checkbox" class="form-check-input" class="get_value1" value="Hipertensi">Hipertensi
</label>
</div>
<div class="checkbox-inline">
<label class="form-check-label">
<input type="checkbox" class="form-check-input" class="get_value1" value="Dm">DM
</label>
</div>
<div class="checkbox-inline">
<label class="form-check-label">
<input type="checkbox" class="form-check-input" class="get_value1" value="KP">KP
</label>
</div>
<div class="checkbox-inline">
<label class="form-check-label">
<input type="checkbox" class="form-check-input" class="get_value1" value="Jantung">Jantung
</label>
</div>
<div class="checkbox-inline">
<label class="form-check-label">
<input type="checkbox" class="form-check-input" class="get_value1" value="Epilepsi">Epilepsi
</label>
</div>
<div class="checkbox-inline">
<label class="form-check-label">
<input type="checkbox" class="form-check-input" class="get_value1" value="Gemeli">Gemeli
</label>
</div>
<div class="checkbox-inline">
<label class="form-check-label">
<input type="checkbox" class="form-check-input" class="get_value1" value="Psikosis">Psikosis
</label>
</div>
<div class="checkbox-inline">
<label class="form-check-label">
<input type="checkbox" class="form-check-input" class="get_value1" value="cacat_bawaan">Cacat Bawaan
</label>
</div>
</div>
<div class="col-md-12 col-sm-12 col-xs-12">
<label>Kebiasaan: </label>
<div class="checkbox-inline">
<label class="form-check-label">
<input type="checkbox" class="form-check-input" class="get_value2" value="merokok">Merokok
</label>
</div>
<div class="checkbox-inline">
<label class="form-check-label">
<input type="checkbox" class="form-check-input" class="get_value2" value="mabok">Minuman Keras
</label>
</div>
<div class="checkbox-inline">
<label class="form-check-label">
<input type="checkbox" class="form-check-input" class="get_value2" value="narkoba">Narkotik
</label>
</div>
<div class="checkbox-inline">
<label class="form-check-label">
<input type="checkbox" class="form-check-input" class="get_value2" value="ob_tenang">Obat Penenang
</label>
</div>
</div>
<div class="col-md-12 col-sm-12 col-xs-12">
<label>Keluahan Fluor Albus: </label>
<div class="checkbox-inline">
<label class="form-check-label">
<input type="checkbox" class="form-check-input" class="get_value3" value="gatal">Gatal
</label>
</div>
<div class="checkbox-inline">
<label class="form-check-label">
<input type="checkbox" class="form-check-input" class="get_value3" value="Berbau">Berbau
</label>
</div>
<div class="checkbox-inline">
<label class="form-check-label">
<input type="checkbox" class="form-check-input" class="get_value3" value="susu">Seperti Susu
</label>
</div>
<div class="checkbox-inline">
<label class="form-check-label">
<input type="checkbox" class="form-check-input" class="get_value3" value="busa_cair">Busa Cair
</label>
</div>
</div>
ajax
<script type="text/javascript">
function simpandata(){
var derita_sakit = $(".get_value").val();
var rw_skt = $(".get_value1").val();
var kebiasaan = $(".get_value2").val();
var keluhan = $(".get_value3").val();
$.ajax({
type : "POST",
data : "id_pemeriksaan="+id_pemeriksaan+"&no_rm="+no_rm+"&id_bidan="+id_bidan+"&umur="+umur+"&alergi_obat="+alergi_obat+"&nama_s="+nama_s+"&umur_s="+umur_s+"&agama_s="+agama_s+"&pndk_s="+pndk_s+"&kerja_s="+kerja_s+"&anak="+anak+"&tahun="+tahun+"&jum_kehamilan="+jum_kehamilan+"&jum_persalinan="+jum_persalinan+"&jum_keguguran="+jum_keguguran+"&hpht="+hpht+"&hpl="+hpl+"&muntah="+muntah+"&nyeri_perut="+nyeri_perut+"&pusing="+pusing+"&nafs_mkn="+nafs_mkn+"&pendarahan="+pendarahan+"&derita_sakit="+derita_sakit+"&rw_skt="+rw_skt+"&kebiasaan="+kebiasaan+"&keluhan="+keluhan+"&passex_istri="+passex_istri+"&passex_suami="+passex_suami+"&bt="+bt+"&paru="+paru+"&sadar="+sadar+"&jantung="+jantung+"&mata="+mata+"&hati="+hati+"&leher="+leher+"&sb="+sb+"&payudara="+payudara+"&genetelia="+genetelia,
url : 'http://localhost:8080/klinikcm/modules/anc/insert.php',
success : function(hasil){
loaddata();
window.location.href = "index.php?page=anc";
alert('Data Pelayanan ANC Berhasil Disimpan');
}
});
}
</script>
action insert
$data1 = $_POST['derita_sakit'];
$data2 = $_POST['rw_skt'];
$data3 = $_POST['kebiasaan'];
$data4 = $_POST['keluhan'];
mysqli_query($db, "INSERT INTO anc_ku(id_pemeriksaan,muntah,nyeri_perut,pusing,nfsu_mkn,pendarahan,derita_sakit,rw_sktkeluarga,kebiasaan,keluhan,ps_sexistri,ps_sexsuami) VALUES ('$id_pemeriksaan','$muntah','$nyeri_perut','$pusing','$nafs_mkn','$pendarahan','".$data1."','".$data2."','".$data3."','".$data4."','$passex_istri','$passex_suami')");
mohon bantuannya kak :)
0
1 Jawaban:
undefined didapat karena variable yang kamu buat isinya kurang tepat dalam menyeleksi element input HTML. perhatikan, di dalam satu element kamu hanya perlu menulis satu atrribute "class" yang nilainya bisa ada beberapa, jangan menulis lebih dari satu attribute
1