Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Jquery API value not working in input textarea

I am working in a crypto currency live price page. I am using Coingekho api for it. It is not working in
$<input type="number" id="bitcoin" value=""/> but it is woring in <h2 id="bitcoin"></h2>. I need it in <input type="number" id="bitcoin" value=""/>. Also I need all decimal value of price like $19755.25725.

var btc = document.getElementById("bitcoin");
var ltc = document.getElementById("litecoin");
var eth = document.getElementById("ethereum");

var liveprice = {
  "async": true,
  "scroosDomain": true,
  "url": "https://api.coingecko.com/api/v3/simple/price?ids=bitcoin%2Clitecoin%2Cethereum&vs_currencies=usd",

  "method": "GET",
  "headers": {}
}

$.ajax(liveprice).done(function(response) {
  btc.innerHTML = response.bitcoin.usd;
  ltc.innerHTML = response.litecoin.usd;
  eth.innerHTML = response.ethereum.usd;

});
    $<input type="number" id="bitcoin" value=""/>
    $<h2 id="litecoin"></h2>
    $<h2 id="ethereum"></h2>
<script  src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<input> elements don’t have innerHTML, since they’re not containers. You need to set btc.value.

var btc = document.getElementById("bitcoin");
var ltc = document.getElementById("litecoin");
var eth = document.getElementById("ethereum");

var liveprice = {
  "async": true,
  "crossDomain": true,
  "url": "https://api.coingecko.com/api/v3/simple/price?ids=bitcoin%2Clitecoin%2Cethereum&vs_currencies=usd",

  "method": "GET",
  "headers": {}
}

$.ajax(liveprice).done(function(response) {
  btc.value = response.bitcoin.usd;
  ltc.innerHTML = response.litecoin.usd;
  eth.innerHTML = response.ethereum.usd;

});
    $<input type="number" id="bitcoin" value=""/>
    $<h2 id="litecoin"></h2>
    $<h2 id="ethereum"></h2>
<script  src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading