Problem storing value in an array textbox

Can someone please tell me what is wrong with this code

function testing(str)
    {
        var str=""; 
        var e=document.getElementsByName("complainthx[]");
        for(var i=0; i<e.length;i++)
        {
            //var f=e[i];
        return document.getElementsByName('complainthx[]')[i].value=str;
        }

        
    }

what do you expect it to happen that deosn’t work?

the value of str is not passing into the document.getElementsByName(‘complainthx’)[i] control

Is the function being called at all?

Having a return inside a for doesn’t seem right.

If you want only the first, why have a for loop?

If you want them all, move the return to after the loop.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.