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>