html - Javascript conversion not working -
when click on mbtc , try click btc doesn't work. if go bit or sat , btc works fine. don't understand why isn't converting mbtc btc. maybe convertmbtc function?
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>
at beginning of bitcoinconversion()
have:
if (currentunit != mbit)
so doesn't if last clicked on mbtc
. line should be:
if (currentunit != btc)
Comments
Post a Comment