Home > Blockchain >  onkeyup textbox, get value from span javascript
onkeyup textbox, get value from span javascript

Time:05-06

How can I get value from span using dynamic id and show in a text input?

I have this span id

<span id="unitCost{{$data->product_id}}">700</span>

    **Onkeyup I want to get the span data.**
   
<input type="number"  id="productId{{$data->product_id}}" onkeyup="calculate({{$data->product_id}})" min="0">

Javascript I tried

   calculate = function(id)
{
 var qty = document.getElementById('unitCost' id).value;
    alert (qty);
}

CodePudding user response:

use innerText instead of value

calculate = function(id)
{
 var qty = document.getElementById('unitCost' id).innerText;
    alert (qty);
}
  • Related