0

I have a array of input fields I need to select for a jQuery change event.

<input id="LandDescriptionItems_0__Acres" name="LandDescriptionItems[0].Acres" ...
<input id="LandDescriptionItems_1__Acres" name="LandDescriptionItems[1].Acres" ...
<input id="LandDescriptionItems_2__Acres" name="LandDescriptionItems[2].Acres" ...

etc

Currently there are 11 of these elements. I need to wire up a jQuery change() event so I can get a sum of them any time one gets changed. Something like:

_$form.find('#LandDescriptionItems_0__Acres').change(function(e) {
    e.preventDefault();

    ...

});

It's really just the selector I'm stumped on. Is it as simple as using wildcards? Or is there a better way?

rwkiii
  • 5,716
  • 18
  • 65
  • 114
  • It would be easier if you gave them all a unique class... – Nick May 23 '20 at 23:09
  • @Nick You might be right. I create those inputs in a loop. I won't need any CSS. I'll go that route for now because it likely is easiest. Do you know what this is called specifically? I'd like to do a Google search and read up. Thanks. – rwkiii May 23 '20 at 23:17
  • Good question... I'm not sure myself how I would search for it. – Nick May 23 '20 at 23:19
  • You can use part of id in jquery selector `$('input[id^="LandDescriptionItems_"]')` – Denis Stukalov May 23 '20 at 23:40

0 Answers0