-1

I have this HTML

<input type="text" name="object[A][Name]">
<input type="text" name="object[A][Description]">
<input type="text" name="object[B][Name]">
<input type="text" name="object[B][Description]">

but when i try to get with:

var x = document.getElementsByName("object");
var x = document.getElementsByName("object[]");
var x = document.getElementsByName("object[][]");
var x = $("[name='object']");
var x = $("[name='object[]']");
var x = $("[name='object[][]']");

x is empty

I need get A, Name/Description and value

Normally I process this names in PHP like this:

foreach($_POST['object'] as $objectgroup=>$value)
{
  /* work here */
}
2
  • Why do you expect a different result? Please explain. Commented Aug 31, 2016 at 18:37
  • Here's the link to the API with all the available selectors api.jquery.com/category/selectors. Commented Aug 31, 2016 at 18:38

2 Answers 2

0

Use ^= to match the starting string:

var x = $("[name^='object']"); // Get all elements
var x = $("[name^='object[A']"); // Get only "object[A]" elements
var x = $("[name='object[A][Description]']"); // Matches full element name

Demo

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

Comments

0

You want to select inputs whose name attribute starts with "object", so use the ^= operator (docs):

var x = $('input[name^=object]');

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.