0

Hi guys,

I want to assign something into label via JS but code below doesn't work for array. Do I miss something?

Thanks in advance

<script>
function calculate_cost(whichlabel){
  document.getElementById('text_cost['+whichlabel+']').innerHTML = 'show me in label below';
}


<input type="text" name="text_qty[]" value="0" size="3" maxlength="5" style="text-align:center;" onkeyup="calculate_cost(0)" />

<label id="text_cost[]">0.00</label>
2
Contributors
4
Replies
5
Views
5 Years
Discussion Span
Last Post by veledrom
0

Maybe something like this. You are using arrays, so you have to define them in your function.

function motor(){
    num = document.getElementyById("input").value;
    var qnt = new Array();
    qnt[0] = num;
    var n = qnt.length;
    var show = new Array();
    for(i=0;i<n;i++){
        show[i] = getElementTagName("label");
        show[i].innerHTML = qnt[i];
    }
}
<a onclick="motor()" id="input">

UNTESTED!!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.