Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 140788

How to get the data of a javascript generated input into arrays?

$
0
0

The button .add-fields will generate new name and address input using js.
The problem is I cannot get the values of inputs generated by the js
This is the original input from laravel blade.php

<input type="text" name="name[]" />
<input type="text" name="name[]" />

This is the javascript code which generates new inputs

$('.add-fields').on('click', add);

function add() {
    var new_request_no = parseInt($('#total_request').val()) + 1;
    var new_input = $("<input type='text' name='name[]'' /><input type='text' name='name[]'' />");

    $('#new_request').after(new_input);

    $('#total_request').val(new_request_no);
}

And this is from the controller

$data = array();
        $name = $request->input('name');
        $address = $request->input('address');


        for ($i = 0; $i < count($name); $i++) {
            $data[] = array(
                'name' => $request->input('$name[$i]'),
                'address' => $request->input('$address[$i]'),
            );
        }

        $info = new InfoModel;
        $info->data = json_encode($data);


        $info->save();

Viewing all articles
Browse latest Browse all 140788

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>