Kamis, 26 Desember 2019

javascript confirm href or confirm submit form

<td class="xfit">
<a href="?x=1" onclick="return confirm('Yakin akan menghapus <? echo $rw->nama_barang ?> ?')"?>
 <? echo $i?>
</a>
</td>

Javascipt and jQuery addEventListener

<script> var bayars=document.getElementsByClassName("bayar"); for(var j = 0; j < bayars.length; j++) { bayars[j].addEventListener('keydown', function (e) { var key = e.which || e.keyCode; if (key === 13) { // 13 is enter var person = prompt("Yakin telah menerima pembayaran sebesar \n"+document.getElementById("dibayar").innerHTML); if (person == null || person == "") return; for(var i = 0; i < bayars.length; i++) { if(bayars[i].value > 0){ //alert(bayars[i].form.id); var data = $("#"+bayars[i].form.id).serialize(); $.ajax({ type : 'POST', url : '?ajax=admin/keuangan/bayar.php&opr='+person, data : data, success : function(response) { setTimeout('top.window.location.href = ""; ' , 500); } }); } } } if (key === 39) { // 13 is right button //var person = aler var nextid=this.id.replace("tdi", ""); nextid = nextid*1 + 1; document.getElementById("tdi"+nextid).focus(); } if (key === 37) { // 13 is right button //var person = aler var nextid=this.id.replace("tdi", ""); nextid = nextid*1 - 1; document.getElementById("tdi"+nextid).focus(); } }); bayars[j].addEventListener('keyup', function (e) { var rupiah=0; for(var i = 0; i < bayars.length; i++) { rupiah += bayars[i].value * 1; } var reverse = rupiah.toString().split('').reverse().join(''), ribuan = reverse.match(/\d{1,3}/g); ribuan = ribuan.join('.').split('').reverse().join(''); document.getElementById("dibayar").innerHTML=ribuan; }); } </script>



<script>
document.getElementById("myBtn").addEventListener("click", displayDate);

function displayDate() {
  document.getElementById("demo").innerHTML = Date();
}
</script>
-----------------------------------------------------------------------
if using jquery
-----------------------------------------------------------------------
$("td.layanan").dblclick(function (e){
        e.stopPropagation();      //<-------stop the bubbling of the event here
        var nik = this.closest("tr").cells[1].innerHTML;
        top.window.location.href = "?pass="+nik;
});

Sabtu, 21 Desember 2019

ajax and response

function popup(idbrg){
$.ajax({ type : 'POST', url : '?plain=app/barang-harga.php&act=load', data : {id:idbrg, act:"load"}, success : function(response){ var json=JSON.parse(response); var fmtarget=document.forms['fmmodal']; for(key in json){ if(json.hasOwnProperty(key))fmtarget["a["+key+"]"].value=json[key] } $("#popup").modal(); } });
}


    if($_GET[act]=="load"){
        $o=mysqli_fetch_object($db->query("select * from ijp_barang where idx='$_POST[id]'"));
        echo ' {
            "nama_barang" : "'.$o->nama_barang.'",
            "hrg_beli": "'.$o->hrg_beli.'",
            "isi_kemasan": "'.$o->isi_kemasan.'",
            "satuan_kemasan": "'.$o->satuan_kemasan.'",
            "vendor" : "'.$o->vendor.'",
            "idx" : "'.$o->idx.'"
        }';
    }






$.post("test.php",{nama:"person"}).done(function(response){
            alert(response);
});

<button class="btn btn-primary" onclick="simpan(this.form,event)" value="datang-f138.php">Selesai</button>

function simpan(fm,e){ e.preventDefault();
    $.post(".?ajax=app/save3",$(fm).serialize()).done(function(response){
        var idxsrt="<? echo $_GET[srt]?>";
        document.getElementById("hrefclose").href="keterangan=domisili?srt="+response.split('|')[0];
        $('#printmodal').modal();
        fmcetak=document.forms['fmcetak'];
        fmcetak.action='.?ajax='+'../cetak/keterangan'+'&srt='+response.split('|')[0]+'&src=';
        fmcetak['nosur'].value=response.split('|')[1];
        fmcetak.submit();
    });
}

Foto Propades