0

i have a form which contains multiple input text box that will take emails.

<li style="text-decoration: none" id="email1"><input type="text" name="email[]" /></li>
<li style="text-decoration: none" id="email2"><input type="text" name="email[]" /></li>

There will also be option to add more input fields.

i want to loop over each email so as to perform pre-post validation.

How do i loop over email[] using jquery

3 Answers 3

2

Use an attribute selector to find them, and each to loop through them:

$('input[name="email[]"]').each(function() {
    // ...
});

Live Example | Source

Sign up to request clarification or add additional context in comments.

Comments

0

To loop over, and perform actions upon, the elements, use each():

$('input[name="email[]"]').each(function(i,e){
    // i is the index of the current element within the collection,
    // e is the DOM node node
});

Simple demonstrative example of how to use.

The input is an element-type selector, the [name="email[]"] is the element-equals selector.

References:

Comments

0

Use the following. You need to escape '[' and ']' characters Hope it will help you.

$('input[name="email\\[\\]"]').each(function(){

})

1 Comment

Actually, you don't need to escape those characters (any more, but I don't believe it does any harm to do so).

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.