-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 */
}
KevBot
  • 16,116
  • 5
  • 48
  • 66
RCabral
  • 33
  • 5

2 Answers2

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

DontVoteMeDown
  • 20,534
  • 10
  • 70
  • 102
0

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

var x = $('input[name^=object]');
James
  • 106,638
  • 30
  • 159
  • 173