html - JavaScript Adding a numeric generated value onto a current set value -
i have function generates random number me between 2 values set myself. here's code.
<script> function coinsearned(){ var worth = document.getelementbyid("earned"); var coins=math.floor(math.random()*10000+1000); earned.value = coins; } </script> this works perfect. now, have text bubble represents users balance, perfect me. here's code.
<input class="balance" id="balance" type=text" value="20000" readonly/> i add new button when clicked transfer generated number found above ^^ onto balance text stated there ^. how happen using javascript function preferably when button clicked have onclick="funtion();" add generated number current balance , display new balance.
thanks in advance :)
you can access current amount using value attribute.
function coinsearned(){ var current = document.getelementbyid("balance"); var coins = math.floor(math.random()*10000+1000); current.value = +current.value + coins; } document.getelementbyid("mybutton").onclick = coinsearned;
Comments
Post a Comment