You can capture a value from the radio button via ajax

Asked

Viewed 68 times

0

<div class="btn-group btn-group-toggle col-xs-5" data-toggle="buttons">
            <button type="radio" name="tipoTransacao" id="tipoTransacao" value="1" class="btn btn-success" ><i class='fa fa-arrow-up'></i>Entrada</button>
            <button type="radio" name="tipoTransacao" id="tipoTransacao" value="2" class="btn btn-danger">Saída<i class='fa fa-arrow-down'></i>Saída</button>
          </div>

and I’m trying to make the catch like this:

function salvar(e){
e.preventDefault();
var fk_idConta = $(this).find('select[name=fk_idConta]').val();

var tipoTransacao =  $("button[name='tipoTransacao']:checked").val();
var demo8 = $(this).find('input[name=demo8]').val();
var dataTransacao = $(this).find('input[name=dataTransacao]').val();
var meioTransacao = $("input[name='meioTransacao']:checked").val();
var descTransacao = $(this).find('textarea[name=descTransacao]').val();

1 answer

1

Elements <button> do not have value. Even if you declare the values in HTML, they will not exist in Javascript. The "correct" way to use radio Buttons is to give name different for them, and then validate by name, not by value.

However, if you absolutely need to work that way, you can take the value of value directly from the attribute declared in HTML with $("button[name='tipoTransacao']:checked").attr('value')

Browser other questions tagged

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