0

I'm trying to iterate through an array of textareas on my page with ClassName TextInput and change their values (innerHTML). The function I wrote is as follows-

    function init() {
        var TextInput[] = document.getElementByClassName("TextInput"); //line 12
        for(var i = 0; i < TextInput.length; i++) {
            TextInput[i].innerHTML = "N/A";
        }
    }

Firefox 18.0.2's debug console says SyntaxError: missing ; before statement on line 12.

What is wrong with my code and how can I achieve what I'm trying to do?

1 Answer 1

2

You don't need to add [], just

var TextInput = document.getElementByClassName("TextInput"); //line 12

Edit: And as @Benjamin pointed out, the function name is missing a s.

This should work:

var TextInput = document.getElementsByClassName("TextInput"); //line 12
Sign up to request clarification or add additional context in comments.

4 Comments

Also, the function name is getElelentsByClassName
Did it and now it says- TypeError: document.getElementByClassName is not a function on line 12.
@BenjaminGruenbaum It worked. getElementsByClassName did the trick. Thanks.
@SamikSengupta The bug you notices was pointed out by @ Dogbert , I just notices another thing missing . You should accept his answer.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.