How can I get value from span using dynamic id and show in a text input?
I have this span id
JavaScript
x
1
1
<span id="unitCost{{$data->product_id}}">700</span>
JavaScript
1
4
1
**Onkeyup I want to get the span data.**
2
3
<input type="number" class="form-control total_cost " id="productId{{$data->product_id}}" onkeyup="calculate({{$data->product_id}})" min="0">
4
Javascript I tried
JavaScript
1
6
1
calculate = function(id)
2
{
3
var qty = document.getElementById('unitCost'+id).value;
4
alert (qty);
5
}
6
Advertisement
Answer
use innerText
instead of value
JavaScript
1
6
1
calculate = function(id)
2
{
3
var qty = document.getElementById('unitCost'+id).innerText;
4
alert (qty);
5
}
6