Tampilkan postingan dengan label Javascipt. Tampilkan semua postingan
Tampilkan postingan dengan label Javascipt. Tampilkan semua postingan

Selasa, 10 November 2020

Popup Submit

document.getElementById("btnsumbit").addEventListener("click",function(){
	$('#popup').modal('hide');
	$.post("?act=save",$(this.form).serialize()).done(function(response){
		console.log(response);
		if(response.split("<<<")[1]==" reload ")location.reload(true);
	});
	event.preventDefault();
});
          
fmtarget.querySelectorAll('input[type=text]').forEach(function(el){
	console.log(el.name);
	el.value='';
});

Rabu, 04 November 2020

Falidate Form

 function validateForm() {

var ct=0;

var inputs=document.getElementsByTagName("input");

for (i = 0; i < inputs.length; i++) {

try{

if(inputs[i].value == '' && inputs[i].title.toLowerCase() == 'penting') {

ct = 1;

inputs[i].style.background= "blue";

}

}catch(e){}

}

    if (ct != 0) {

        alert("Yang Berwarna kuning harus di isi");

        return false;

    }

}










x = document.querySelectorAll(".example");

  for (i = 0; i < x.length; i++) {

    x[i].style.backgroundColor = "red";

  }

Minggu, 04 Oktober 2020

Rabu, 30 September 2020

Javascript event listener on all class

  const divs = document.querySelectorAll('.hitung');

or

 const divs = document.querySelector('button[type="submit"]');

divs.forEach(el => el.addEventListener('keyup', event => {

var fm=el.form;

fm['a[harga1]'].value=fm["a[bruto]"].value - (fm["a[diskon1]"].value * fm["a[bruto]"].value / 100);

fm['a[harga2]'].value=fm["a[harga1]"].value - (fm["a[diskon2]"].value * fm["a[harga1]"].value / 100);

fm['a[harga3]'].value=fm["a[harga2]"].value - (fm["a[diskon3]"].value * fm["a[harga2]"].value / 100);

fm['a[harga]'].value=fm['a[harga3]'].value;


event.preventDefault();

  //console.log(event.target.classList[1]);

}));


Sabtu, 01 Agustus 2020

Radio Button Event Handler

var rad = document.myForm.myRadios;
var prev = null;
for (var i = 0; i < rad.length; i++) {
    rad[i].addEventListener('change', function() {
        (prev) ? console.log(prev.value): null;
        if (this !== prev) {
            prev = this;
        }
        console.log(this.value)
    });
}
<form name="myForm">
  <input type="radio" name="myRadios"  value="1" />
  <input type="radio" name="myRadios"  value="2" />
</form>

Sabtu, 25 Juli 2020

href confirmation

html
<a href="delete.php?id=22" onclick="return confirm('Are you sure?')">Link</a>
javascript
<script>
function hps(id){
  if (window.confirm('Yakin akan menghapus?'))
  {
    $.post("",{hps:id} ).done(function(response){
      var wnd = window.open("about:blank", "", "_blank");
      wnd.document.write(response);
      //var node = response.split("<<<");
      //if(node[1]==" ok "){location.reload(true);}
    });  
  }else{
      // They clicked no
  }
}
</script>


aa

html
<a href="delete.php?id=22" onclick="return confirm('Are you sure?')">Link</a>
javascript
<button onclick="if(confirm('Are you sure?')) saveandsubmit(event);"></button>


atau


<button onclick="return confirm('Are you sure?')?saveandsubmit(event):'';"></button>

Sabtu, 18 Juli 2020

Javascript Post Form

a
<script>
/**
 * sends a request to the specified url from a form. this will change the window location.
 * @param {string} path the path to send the post request to
 * @param {object} params the paramiters to add to the url
 * @param {string} [method=post] the method to use on the form
 */

function f_post(path, params, method='post') {

// The rest of this code assumes you are not using a library.
// It can be made less wordy if you use one.
const form = document.createElement('form');
form.method = method;
form.action = path;

for (const key in params) {
  if (params.hasOwnProperty(key)) {
    const hiddenField = document.createElement('input');
    hiddenField.type = 'hidden';
    hiddenField.name = key;
    hiddenField.value = params[key];

    form.appendChild(hiddenField);
  }
}

document.body.appendChild(form);
form.submit();
}
</script>
a

Minggu, 05 Juli 2020

Javascript Jquery Prevent Form Submit

PHP CODE


javascript
  <script>
  var inputs=document.getElementsByTagName("*");
  for (i = 0; i < inputs.length; i++) {
    try{
      if(inputs[i].name.includes("a[")){
        inputs[i].value = "sss"+inputs[i].name.replace("a[", "[a|");
      }
      if(inputs[i].type=='submit'){
        inputs[i].addEventListener("click", function(event){
          $.post("?input&act=save",$(this.form).serialize()).done(function(response){
console.log(response);
            //var node = response.split("<<<");
            //if(node[1]==" ok "){location.reload(true);}
            var wnd = window.open("about:blank", "", "_blank");
            //wnd.document.write(node[1]);
            wnd.document.write(response);
          });  
        event.preventDefault();
        });
      }
    }catch(e){}
  }
  </script>
d
<script>
      function addsiswa(id){
        $.post("",{id:id} ).done(function(response){
            var node = response.split("<<<");
            if(node[1]==" ok "){location.reload(true);}
            //var wnd = window.open("about:blank", "", "_blank");
            //wnd.document.write(node[1]);
            //wnd.document.write(response);
          });  
      }
</script>
d
d

Sabtu, 04 Juli 2020

Fill Form Field Object with Own Name

s
  <script>
  var inputs=document.getElementsByTagName("*");
  for (i = 0; i < inputs.length; i++) {
    try{
      if(inputs[i].type.toLowerCase() == 'text'  || inputs[i].tagName.toLowerCase() == 'textarea' || inputs[i].tagName.toLowerCase() == 'select') {
        inputs[i].value = inputs[i].name.replace("a[", "[a|");
        inputs[i].name = inputs[i].name.replace("a[", "[a|");
      }
    }catch(e){}
  }

  </script>
s

<script>
  var inputs=document.getElementsByTagName("*");
  for (i = 0; i < inputs.length; i++) {
    try{
      if(inputs[i].name.includes("a[")){
        inputs[i].value = inputs[i].name.replace("a[", "[a|");
      }
    }catch(e){}
  }

  </script>

s

Rabu, 26 Februari 2020

Javascript JSON and ParseJson

JSON result
echo '{"srt":"'.$rw->idx.'","nosur" : "'.$rw->nosur.'","kode": "'.$rw->kode.'", "cetak" : "'.$rw->cetak.'", "url" : "'.$rw->url.'"}';

Parse It

$.get("?ajax=../cetak/print2&cetak=" + srt,function(response){
        if(response!=""){
            var json=$.parseJSON(response);
            $('#printmodal').modal();                   
            fmcetak=document.forms['fmcetak'];
            fmcetak.action='.?ajax='+loader+'&srt='+srt+'&src='+src;
            fmcetak['nosur'].value=json['nosur'];
            fmcetak.submit();
        }
});

Kamis, 26 Desember 2019

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;
});

Selasa, 08 Agustus 2017

Form Action Popup Windows

[insert_php]
$qs=$_SERVER['QUERY_STRING'];
if($q!=""){
echo "<iframe src='https://script.google.com/macros/s/AKfycbwmZcgYrEN4vVuBVXGyRRfsSZ231PlnKl09A4Rv8sjaf1K3tWAM/exec?".."' width='100%' height='1300' frameborder='0' marginwidth='0' marginheight='0'>Memuat...</iframe>";
}else{
echo "<form action='https://script.google.com/macros/s/AKfycbxTbLgqvRSD_B7IDOLCybhk8tqRJFVGxcwWmiPcKBG6RcHjD1o/exec' method='get'>Silahkan masukkan kode file yang telah anda dapatkan dari email kami kemudian click tombol download";
$q=$qs;
if($q[0]=="")$q[0]="desa";
echo "<input name='$q[0]' class='form-control' type='text' placeholder='kode_file' value='$q[1]'/>";
}
[/insert_php]
<input type="submit" value="Download" class="btn btn-success" id="submiter" />
</form>
<script language="javascript">
var myForm = document.getElementById('formID');
myForm.onsubmit = function() {
    var w = window.open('about:blank','Popup_Window','toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=400,height=300,left = 312,top = 234');
    this.target = 'Popup_Window';
};
function getQueryStringValue (key) {
  return decodeURIComponent(window.location.search.replace(new RegExp("^(?:.*[&\\?]" + encodeURIComponent(key).replace(/[\.\+\*]/g, "\\$&") + "(?:\\=([^&]*))?)?.*$", "i"), "$1"));
};
//if(getQueryStringValue("idf"))document.getElementById("submiter").click();
</script>
<hr />

[insert_php]

if($q[1]!=""){
echo "<iframe src='https://script.google.com/macros/s/AKfycbwmZcgYrEN4vVuBVXGyRRfsSZ231PlnKl09A4Rv8sjaf1K3tWAM/exec?".$_SERVER['QUERY_STRING']."' width='100%' height='1300' frameborder='0' marginwidth='0' marginheight='0'>Memuat...</iframe>";
}else{
Echo "Jika anda belum memiliki kode file download, silahkan isi formulir berikut ini :

Informasi tentang cara mendapatkan aplikasi akan kami kirim via sms / telp / whatsapp / telegram / email.


<iframe src='https://docs.google.com/forms/d/e/1FAIpQLSdog7f-52zhvI3agYgh0q--6wrQ4L6nkTZjRCYzgvX6dINhvQ/viewform?embedded=true' width='100%' height='1300' frameborder='0' marginwidth='0' marginheight='0'>Memuat...</iframe>";
}
[/insert_php]

Senin, 23 Januari 2017

Multiple iFrame With Code Source

Redirect include subfolder

<div id="src">it will show in 2nd frame</div>
<button onclick="isi()" value="ff">fdf</button>

<script>
function isi(){
 var iframe = document.getElementById('target'),
    iframedoc = iframe.contentDocument || iframe.contentWindow.document;

 iframedoc.body.innerHTML =  document.getElementById('src').innerHTML;
}
</script>
<iframe id="frame1" name="f1" align="left" width="200px" height="500px" src="data:text/html;charset=utf-8,%3Chtml%3E%3Cbody%3Efoo%3C/body%3E%3C/html%3E" ></iframe>

<iframe id="target" />
Redirect without subfolder




it will show in 2nd frame

Sabtu, 10 Desember 2016

gogle form trigger on submit

//==============================================
/**
 * Copyright 2015 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

function myFunction() {
  var triggers = ScriptApp.getProjectTriggers();
  for(var i in triggers) {
    ScriptApp.deleteTrigger(triggers[i]);
  }
  ScriptApp.newTrigger("SendHold")
  .forForm(FormApp.getActiveForm())
  .onFormSubmit()
  .create();
}

//=========================================================

function SendHold(e)
{
  try
  {
    //====== MSA LALALU
    var message = "";
    var s = FormApp.getActiveForm().getResponses();
    var items = s[s.length-1].getItemResponses();
    for (var j = 0; j < items.length; j++) {
      var item = items[j];
      message+= item.getItem().getTitle() + "=" + item.getResponse()+ "\n";
      Logger.log('Response #%s to the question "%s" was "%s"',(s.length).toString(),item.getItem().getTitle(),item.getResponse());
    }
    //====== MSA LALALU
    /*
    var s = FormApp.getActiveForm().getResponses();
    var message = "";
    for (var i = 0; i < s.length; i++) {
     
      message='';
      var items = s[i].getItemResponses();
      for (var j = 0; j < items.length; j++) {
        var item = items[j];
        message+= item.getItem().getTitle() + "=" + item.getResponse()+ "\n";
         Logger.log('Response #%s to the question "%s" was "%s"',(i + 1).toString(),item.getItem().getTitle(),item.getResponse());
      }
    }
    */
    GmailApp.sendEmail("xxxxx@gmail.com", "form test","isi" + "\n" +message,{name: 'Form Layanan Desa'})
 
  } catch (e) {
    Logger.log(e.toString());
    MailApp.sendEmail("xxxxx@gmail.com","err log",e.toString() + '\n' + msg);
  }
}

//===================================================

Kamis, 03 Maret 2016