1

Let's say I have some html that looks like this:

<input type="text" name="myInputs[]"> 
<br>
<input type="text" name="myInputs[]"> 
<br>
<input type="text" name="myInputs[]"> 
<br>

I want to use the length of the myInputs array inside some JavaScript code. How do I extract the length of this array? myInputs.length doesn't seem to work

2
  • You have tried accessing it through the form? myform.myInputs.length? Commented Jun 27, 2013 at 0:42
  • Put them in a form then theform['myInputs[]'].length Commented Jun 27, 2013 at 0:43

2 Answers 2

2
console.log(document.formName.elements["myInputs[]"].length);
Sign up to request clarification or add additional context in comments.

Comments

1
document.querySelectorAll("[name='myInputs[]']").length

You can also call querySelectorAll on the form element itself

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.