Read radio and text inputs of the same form

2

I need a light for something I'm doing. within form there are several radios and some text box . I need to get everyone's data within objeto jQuery .

Below is an example of how I do only containing 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:

I need the checks to return the value of it and in the text box return the text

Thank you if anyone can give me a light

    
asked by anonymous 26.09.2017 / 21:55

1 answer

1

You can compose the JQuery value selector $('input:checked, input[type=text]') . That in the case you specified works, since both inputs respond their values to .val() . In this 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>
    
28.09.2017 / 19:31