Read radio and text inputs from the same form

Asked

Viewed 136 times

2

I need a light for something I’m doing. within a form there are several radios and some text box. I need to get all the data inside one objeto jQuery.

below an example of how I do containing only inputs with checked.

var dados = {"result":[]};
        var objRadio = $('input:checked').each(function(){
            dados.result.push({
                            "id_user"     : idUser,
                            "id_varejo"   : idvarejo,
                            "id_pesquisa" : idPesquisa,
                            "id_pergunta" : $(this).attr('name'),
                            "id_resposta" : $(this).val(),
                            "nome"        : nome,
                            "id_status"   : 7
            }); 
        });

and the return would be this :

inserir a descrição da imagem aqui

I need the checks to return its value and the text box returns the text

I’d appreciate it if someone could shed some light

  • Could edit the question and put the return of json?

  • Hi Rafael, the return would be a jquery object.

  • This I understood, I just would like you to pick up the return and put it here (without being image), so we can do the tests based on the return that Voce already has.

  • Hi Rafael, follow an example of the return. {"result":[{"id_user":"1","id_varejo":"2768","id_pesquisa":"3","id_pergunta":"7","id_resposta":"31","nome":"","id_status":7},{"id_user":"1","id_varejo":"2768","id_pesquisa":"3","id_pergunta":"9","id_resposta":"35","nome":"","id_status":7},{"id_user":"1","id_varejo":"2768","id_pesquisa":"3","id_pergunta":"11","id_resposta":"37","nome":"","id_status":7}]}

  • Can you post your working code? on JSFiddle or right here? including HTML and JS

  • It would be impossible because the project is giant :(

  • But you can’t just post that part?

Show 2 more comments

1 answer

1


You can compose the Jquery selector value $('input:checked, input[type=text]'). That in the case you specified it works, since both inputs respond their values to .val(). In case, a textarea would respond to .text().

$('input:checked, input[type=text]').each(function(){
  console.log($(this).attr("type"));
  console.log($(this).val());
});
<input type="checkbox" checked="checked" value="37"/>
<input type="text" value="texto no text"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.