momijigari
momijigari

Reputation: 1598

jQuery, how to get children inputs of a div by name

I have a form, which dynamically creates a lot of name/value pairs of text inputs. Like this:

<div id="specialProperty0ParamsBlock">
    <input type="text" name="paramName" placeholder="Name">
    =<input type="text" name="paramValue" placeholder="Price">
</div>

then I need to iterate over each block and gather params in an object. Like this:

for (var l = 0; l < specialPropertiesCounter; l++) {
    var paramC = 0;
    $('#specialProperty' + l + 'ParamsBlock').each(function (index, _data) {
        data["specialProperties"]["specialProperty" + l]['params']['param' + paramC] =
        {
            'name': $(this).children('input[name="paramName"').val(),
                'value': $(this).children('input[name="paramPrice"').val()
        };
        paramC++;
    });
}

I tried dozens of things, but nothing works.

How can I get data from each input in a single "div" by their "names"? Names of inputs are always the same: "paramName" and "paramPrice"

Upvotes: 4

Views: 24210

Answers (1)

Pranav C Balan
Pranav C Balan

Reputation: 115212

Missing ] in your attribute selector

{
    'name': $(this).children('input[name="paramName"]').val(),
    'value': $(this).children('input[name="paramPrice"]').val()
};

http://api.jquery.com/attribute-equals-selector/

Upvotes: 13

Related Questions