8

I wanted to select the text field based on condition, for example:

if only text field name = sname[] than only put value in it.

For this I used

<input type="text" name="sname[]" />

where name = sname;

//For each name type field in extra add contact module if that i visible.
    $('input[name=' + name + '[]]').each(function() { 

});

But I'm not able to get inside of it. Please suggest how to get into the selection.

2 Answers 2

16
$('input[name="' + name + '[]"]').each(function() {
    $(this).val('Some value');
});
Sign up to request clarification or add additional context in comments.

Comments

2

No need for each loop, you could do it like :

$('input[name="field_name[]"]').val('Some value');

Hope this helps.

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.