'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);
}
Solution 1:[1]
use innerText instead of value
calculate = function(id)
{
var qty = document.getElementById('unitCost'+id).innerText;
alert (qty);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Richie |
