Connect with us

Pay Per Code

Pay Per Code

Calculating an “Instant Offer” using Javascript


Calculating an “Instant Offer” using Javascript

I am currently working on building out a gift card exchange site and wanted to be able to offer the end user an “Instant Offer” for a specific gift card/amount they had entered. When brainstorming back and forth how I should go about tackling this as I wanted it to seem as “Instant” as possible, I settled on using JavaScript to build this out.

Since this is specifically for a gift card exchange platform , I was able to use the same method as calculating a tip for your bill at a restaurant. I set the commission I want to take of the gift card in the script, and then depending on the value of the gift card that has been entered in by the end user, it generates an “Instant Offer” for the end user.


<form action="javascript:void(calc())" class="form-inline">
<div class="form-group"><input id="exampleInputEmail3" class="form-control sell-form" type="email" placeholder="Brand of Gift Card" /></div>
<div class="form-group"><form ><input placeholder="Balance on Card" class="form-control sell-form" id="bill" type="text" /></div>

<input class="btn btn-primary" type="submit" value="Get Offer" />

Commission: <span id="tip"></span>

Instant Offer: <span id="total"></span


function calc() {
var bill = Number(document.getElementById('bill').value);
var tip = bill * .15;
var total_bill = bill - tip;
document.getElementById("tip").innerHTML= "$"+Number(tip).toFixed(2);
document.getElementById("total").innerHTML= "$"+Number(total_bill).toFixed(2);


Continue Reading
You may also like...

More in JS

Instead of using ads, I am having you mine for crypto currency to support this site. Here are your stats:

You can start or stop at anytime but please wait for some accepted hashes before you do.


Popular Posts

To Top