Skip to content
Advertisement

onkeyup textbox, get value from span javascript

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" class="form-control total_cost " 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);
}

Advertisement

Answer

use innerText instead of value

calculate = function(id)
{
 var qty = document.getElementById('unitCost'+id).innerText;
    alert (qty);
}
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement