954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

innerHTML for label element

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>
veledrom
Master Poster
758 posts since Apr 2008
Reputation Points: 42
Solved Threads: 0
 

did you try putting a 0 in the label id?

label id="text_cost[0]">0.00</label>
fobos
Posting Whiz in Training
297 posts since Feb 2009
Reputation Points: 29
Solved Threads: 52
 

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!!

fobos
Posting Whiz in Training
297 posts since Feb 2009
Reputation Points: 29
Solved Threads: 52
 

I'll try it on Monday. Thanks

veledrom
Master Poster
758 posts since Apr 2008
Reputation Points: 42
Solved Threads: 0
 

OK. Putting 0 in it solved problem. Thanks guys

veledrom
Master Poster
758 posts since Apr 2008
Reputation Points: 42
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You