4

Consider this HTML:

<input type="text" name="inputa[42]" value="2012-05-02" />
<input type="text" name="inputb[42]" value="74,178" />

<input type="text" name="inputa[85]" value="2013-02-14" />
<input type="text" name="inputb[85]" value="21,35" />

How to use a jQuery selector to get the value of the input with name inputa[85]?

It would have been very easy if the name wouldn't have contained [85], but now I can't get $("input[name=inputa[85]]") to work which is understandable, but how to solve it (without changing the name attribute)?

Simon Forsberg
  • 13,086
  • 10
  • 64
  • 108
  • 1
    possible duplicate of [jQuery selector for inputs with square brackets in the name attribute](http://stackoverflow.com/questions/2364982/jquery-selector-for-inputs-with-square-brackets-in-the-name-attribute) – Manse Jun 12 '12 at 10:42
  • Sorry, tried to find the answer to this already but I couldn't :) I should have searched for "brackets"! – Simon Forsberg Jun 12 '12 at 10:45

2 Answers2

10

In quotes:

$("input[name='inputa[85]']")

or

$('input[name="inputa[85]"]')
abuduba
  • 4,986
  • 7
  • 26
  • 43
1

You can use $('input[name*="inputa"]') if you don't know the value in brackets or abuduba's answer above.

slash197
  • 9,028
  • 6
  • 41
  • 70