Javascript mBTC to BTC conversion not working

0 votes

When you click on mBTC and then try to click back to BTC it doesn't work. However if you go to bit or sat and back to BTC it works fine. I don't understand why it isn't converting from mBTC to BTC.

var SAT = 0.00000001;
var BIT = 0.000001;
var MBIT = 0.001;
var BTC = 1;
var currentUnit = BTC;

function changeColor(div) {
  document.getElementById('satoshiBox').style.background = '#29b8ff';
  document.getElementById('bitBox').style.background = '#29b8ff';
  document.getElementById('BTCBox').style.background = '#29b8ff';
  document.getElementById('mBTCBox').style.background = '#29b8ff';

  document.getElementById(div).style.background = '#ed546a';
}

function satoshiConvert(input) {
  if (currentUnit != SAT) {
    input.value = (convertBTC(input.value) / SAT).toFixed(0);
    currentUnit = SAT;
    changeColor('satoshiBox');
    btcConvert(input);
  }
}

function bitConvert(input) {
  if (currentUnit != BIT) {
    input.value = (convertBTC(input.value) / BIT).toFixed(2);
    currentUnit = BIT;
    changeColor('bitBox');
    btcConvert(input);
  }
}

function mBTCConvert(input) {
  if (currentUnit != MBIT) {
    input.value = (convertBTC(input.value) / MBIT).toFixed(4);
    currentUnit = MBIT;
    changeColor('mBTCBox');
    btcConvert(input);
  }
}

function bitcoinConversion(input) {
  if (currentUnit != MBIT) {
    input.value = (convertBTC(input.value) / BTC).toFixed(8);
    currentUnit = BTC;
    changeColor('BTCBox');
    btcConvert(input);
  }
}


<div class="bitcoin">
  <div class="rateboxy">
    <input value="1" type="text" name="btc" id="btc" class="rate" onchange="btcConvert(this);" onkeyup="btcConvert(this);" />
  </div>
</div>
<div class="unitBox">
  <div class="smallUnitBox" onclick="satoshiConvert(btc);" id="satoshiBox">sat</div>
  <div class="smallUnitBox" onclick="bitConvert(btc);" id="bitBox">bit</div>
  <div class="smallUnitBox" onclick="mBTCConvert(btc);" id="mBTCBox">mBTC</div>
  <div class="smallUnitBox2" onclick="bitcoinConversion(btc);" id="BTCBox">BTC</div>
</div>
<p id="equals">=</p>
<div class="rateboxy">
  <input value="<?php echo $bitcoinPrice; ?>" type="text" name="cur" id="cur" class="rate" onchange="usdConvert(this);" onkeyup="usdConvert(this);" />
</div>
</div>
</center>
Sep 5, 2018 in Blockchain by digger
• 26,740 points
1,028 views

1 answer to this question.

0 votes

At the beginning of bitcoinConversion() you have:

if (currentUnit != MBIT)

So it doesn't do anything if you last clicked on mBTC. That line should be:

if (currentUnit != BTC)
answered Sep 5, 2018 by slayer
• 29,370 points

Related Questions In Blockchain

0 votes
1 answer

Hyperledger fabric: curl not working to invoke chaincode

Hyperledger Fabric does not offer a REST ...READ MORE

answered Oct 23, 2018 in Blockchain by Perry
• 17,100 points
1,118 views
0 votes
1 answer

Not Able to register a user with Hyperledger-Fabric v1.1 preview

The error: "Certificate not found with AKI 'e729224e8b3f31784c8a93c5b8ef6f4c1c91d9e6e577c45c33163609fe40011' ...READ MORE

answered Jun 16, 2018 in Blockchain by charlie_brown
• 7,720 points
1,877 views
0 votes
1 answer
0 votes
1 answer

Windows not able to recognize Monax command

You probably know this already but support ...READ MORE

answered Jun 22, 2018 in Blockchain by Johnathon
• 9,090 points
796 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,923 views
+1 vote
3 answers

Removing double quotes from a string from JSON response in PHP

Just remove the json_encode call, and it should work: $resp ...READ MORE

answered Sep 12, 2018 in Blockchain by digger
• 26,740 points
45,219 views
0 votes
1 answer

How do I add multiple recipients for transactions via Blockchain API?

Convert the recipes into JSON objects. x = ...READ MORE

answered Jul 6, 2018 in Blockchain by Perry
• 17,100 points
886 views
+1 vote
5 answers

How to solve "truffle: command not found" error in blockchain?

First try restarting the system and then ...READ MORE

answered Jul 16, 2018 in Blockchain by slayer
• 29,370 points
11,947 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP