Jquery create object containing form data

0

I need a hello, I'm trying to create an object containing all the data in a question / answer form.  in php I create the radios like this:

<input type="radio" name="'.$row['id'].'" class="'.$row['id'].'" value="'.$row2['id'].'">&nbsp;'.utf8_encode($row2['resposta']).'<br>';

Now I need to get all these inputs and their values, detail: the table that will receive the result looks like this:

id|id_usuario|id_pesquisa|id_var|id_pergunta|id_resposta.

Thank you if anyone can give me a light !!!

    
asked by anonymous 01.08.2017 / 02:04

1 answer

1

You can create an array with associated key and value example:

var pesquisaArray = { 
id: $('input[name="id"]:checked').val(), // pegar valor de um radiobox
id_usuario: 200, 
id_pesquisa: $('#id_pesquisa').val() // valor com id id_pesquisa
//etc// 
};

You can change the value of a key as follows:

pesquisaArray.id = 20;

or

pesquisaArray["id"] = 20;

To loop through the array you can use the for in

example:

for (var chave in pesquisaArray) {
  console.log("chave " + key + " tem valor  " + pesquisaArray[chave]);
}
    
01.08.2017 / 14:21