Advertisement
endrasgusti

Untitled

Nov 13th, 2017
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.88 KB | None | 0 0
  1. <script>
  2. var thoudelim = ",";
  3.  var decdelim = ".";
  4.  var curr = " ";
  5.  var d=document;
  6.  
  7.  function haltnondigit(e) {
  8.   var allowkey=Array(48,49,50,51,52,53,54,55,56,57,8,9,188,190,45,46,13,33,34,35,36,37,38,39,40,112,113,114,115,116,117,118,119,120,121,123);
  9.   if(allowkey.indexOf(e.keyCode)==-1) return false;
  10.   return true;
  11.  }
  12.  function format(s,r) {
  13.   s=Math.round(s*Math.pow(10,r))/Math.pow(10,r);
  14.   s=String(s);s=s.split(".");var l=s[0].length;var t="";var c=0;
  15.   while(l>0){t=s[0][l-1]+(c%3==0&&c!=0?thoudelim:"")+t;l--;c++;}
  16.   s[1]=s[1]==undefined?"0":s[1];
  17.   for(i=s[1].length;i<r;i++) {s[1]+="0";}
  18.   return curr+t+decdelim+s[1];
  19.  }
  20.  function input_focus(t) {
  21.   t.value=t.getAttribute('ref');t.select();
  22.  }
  23.  function input_keydown(t,e) {
  24.   return haltnondigit(e);t.value=t.getAttribute('ref');
  25.  }
  26.  function input_keyup(t,s) {
  27.   t.setAttribute('ref',t.value);
  28.   if(s=="qty") {
  29.    var temp=parseFloat(t.parentNode.nextSibling.firstChild.getAttribute('ref'))*t.value;
  30.    t.parentNode.nextSibling.nextSibling.firstChild.setAttribute('ref',temp);
  31.    t.parentNode.nextSibling.nextSibling.firstChild.innerHTML=format(temp,2);
  32.   }
  33.   else if(s=="harga") {
  34.    var temp=parseFloat(t.parentNode.previousSibling.firstChild.getAttribute('ref'))*t.value;
  35.    t.parentNode.nextSibling.firstChild.setAttribute('ref',temp);
  36.    t.parentNode.nextSibling.firstChild.innerHTML=format(temp,2);
  37.   }
  38.   calc_total();
  39.  }
  40.  function input_onblur(t) {
  41.   t.value=format(t.value,2);
  42.   return false;
  43.  }
  44.  function calc_total() {
  45.   var x=d.getElementsByTagName("DIV");
  46.   var total=0;
  47.   for(i=0;i<x.length;i++) {
  48.    if(x[i].id=="subtotal") total+=isNaN(parseFloat(x[i].getAttribute("ref")))?0:parseFloat(x[i].getAttribute("ref"));
  49.   }
  50.   d.getElementById("total").innerHTML=format(total,2);
  51.  }
  52. function MM_openBrWindow(theURL,winName,features) { //v2.0
  53.   window.open(theURL,winName,features);
  54. }
  55. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement