Morgari Morgari - 29 days ago 15
Javascript Question

Calculator Script or Plugin

I'm looking for the Calculator Plugin (for Wordpress) or Script which should work in such a way:

Should be only one field where user can type the number of my product (Instagram Likes). And depending on the number the cost changes.

I'v got the variety of prices for different Likes number. For example:


  • 1-10000 likes = 0,0009 per 1 like

  • 10001-50000 = 0,0008 per 1 like etc



And if the user type the number 5555 it should automatically count 5555*0.0009

Could you, please, help me?

Answer

You can use this one.

function priceCalculation(a){
   if(a <= 10000){
     return 0.0009;
   }else if(a >= 10001 && a <= 25000 ){
     return 0.0008;
   }else if(a >= 25001 && a <= 50000 ){
     return 0.0007;
   }else if(a >= 50001 && a <= 100000 ){
     return 0.0005;
   }else{
     return 0.0004;
   }
}


$('#likecount').keyup(function(){
  var price = priceCalculation($(this).val());
  console.log(price)
  var total = $(this).val() * price;
  $('#output').text(total.toFixed(4));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<input type="text" id="likecount" />
<p>Price: <span id="output"></span></p>

Comments