kura2yamato

bobot

May 4th, 2025
342
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 3.16 KB | Source Code | 0 0
  1. /*script dinamic003.js */
  2. jq112(function($) {/*tidak disarankan*/
  3.     jq112(document).on({/*chShow*/
  4.         click: function() {
  5.             checkInfo( );
  6.             if ($(this).is(":checked")){
  7.                 objDiv = $(this).parent().find("div");
  8.                 showLog( objDiv);
  9.                 objDiv.removeClass('hide');
  10.                 showLog("checked");
  11.             }else{
  12.                 objDiv = $(this).parent().find("div");
  13.                 objInput = $(this).parent().find(".inpBobot");
  14.  
  15.                 objInput.val(0);
  16.                 objDiv.addClass('hide');
  17.                 showLog("not checked");
  18.             }
  19.  
  20.       }
  21.     }, ".chShow");
  22.    
  23.     jq112(document).on({//.inpBobot
  24.         change: function() {
  25.             checkInfo(this);
  26.         }
  27.  
  28.     }, ".inpBobot");    
  29. });
  30.  
  31. function checkInfo(obj){
  32.     maxNum=100;
  33.     numActive=0;
  34.     jq112("#btnSimpan").removeClass("btnWarning");
  35.     try {
  36.         numChange= parseInt( jq112(obj).val() );
  37.     }catch(err) {    
  38.         numChange =0;
  39.     }
  40.     iCheck=0;
  41.     minCheck=3;
  42.     maxCheck=5;
  43.     jq112( ".inpBobot" ).each(function() {
  44.       numActive += parseInt( jq112(this).val() );
  45.       jq112(this).removeClass("redBorder");    
  46.     });
  47.  
  48.     jq112( ".chShow" ).each(function() {
  49.         if (jq112(this).is(":checked")){
  50.           iCheck++;
  51.         }
  52.     });
  53.  
  54.     if(iCheck < minCheck){
  55.         nodeWrite("infoBobot", "Masukkan minimal "+minCheck+" input<br/>",1);
  56.         jq112("#btnSimpan").addClass("btnWarning");
  57.     }else if(iCheck > maxCheck){
  58.         nodeWrite("infoBobot", "Masukkan maximal "+maxCheck+" input<br/>",1);
  59.         jq112("#btnSimpan").addClass("btnWarning");
  60.     }else{
  61.         nodeWrite("infoBobot", "",1);
  62.     }
  63.     //nodeWrite("infoBobot", "Anda menginput:"+iCheck );
  64.  
  65.     if(numActive > maxNum){
  66.         nodeWrite("infoBobot", "Nilai Bobot :"+numActive+"\nBatas Maximal:"+maxNum   );
  67.         nodeWrite("infoBobot", "<br/>silahkan di review kembali:"+ numInput);
  68.         numInput = maxNum - (numActive - numChange);
  69.         jq112(this).val( numInput ).addClass("redBorder");
  70.         jq112("#btnSimpan").addClass("btnWarning");
  71.         //alert("Nilai Bobot :"+numActive+"\nBatas Maximal:"+maxNum);
  72.     }else if(numActive < maxNum){
  73.         nodeWrite("infoBobot", "Nilai Bobot terinput:"+numActive );
  74.         numInput = maxNum - (numActive);
  75.         if(numInput!=0){
  76.             nodeWrite("infoBobot", "<br/>Bobot yang dapat di input:"+ numInput);
  77.         }
  78.         showLog([numActive,maxNum]);
  79.         jq112("#btnSimpan").addClass("btnWarning");
  80.     }else if(numActive < maxNum){
  81.         nodeWrite("infoBobot", "<br/>Bobot dapat diproses" );
  82.     }
  83.     return ;
  84. }
  85.  
  86. function showLog( objLog ){
  87.     try {
  88.         //console.log( objLog );
  89.     }
  90.     catch(err) {    
  91.     /*console.log not work here*/
  92.     }
  93.     return ;
  94. }//function showLog()
  95.  
  96. function nodeWrite(objName, content, clean){
  97.     let element = document.getElementById(objName);
  98.     if(clean){
  99.         while ( element.lastChild ) {
  100.             element.removeChild( element.lastChild );
  101.         }
  102.     }
  103.  
  104.     element.insertAdjacentHTML( "beforeend", content );
  105.     return ;
  106. }
Advertisement
Add Comment
Please, Sign In to add comment