Add Input with Jquery and how to get input data

1

I have 1 button in JS that creates input. Only I can not get this input data. I can create each input with a different name , but I have no idea how can I get these values from php . I tried to send the var add to loop, but it can not get the final value.

Here is the JSFIDDLE button and different name.

    
asked by anonymous 18.02.2015 / 15:42

1 answer

0

Friend, the most correct way to do PHP would be by setting the value of the input as a Array .

That is. Instead of doing this:

var add = 1;
function add_fields() {
    var d = document.getElementById("content");
    add++;
    d.innerHTML += "<br /><label class='tooltips'>A ser excluído "+add+": <input type='text' name='solicitacao"+add+"'/></label>";
}

You should do this:

var add = 1;
function add_fields() {
    var d = document.getElementById("content");
    add++;
    d.innerHTML += "<br /><label class='tooltips'>A ser excluído "+add+": <input type='text' name='solicitacao[]'/></label>";
}

Simply put: we replace "solicitacao" + add with "solicitacao[]" .

When doing this, PHP will access the value of solicitacao[] through $_POST['solicitacao'] , and this will return a Array with all the entered data.

In this way, this operation becomes more dynamic, without the use of counters to do it.

Remembering that these inputs must be declared inside the form ( <form> ), in order to send the submission of values.

    
18.02.2015 / 16:15