Send two variable of a radius and a select using JQuery

0

I want to send two variables using JQuery, The first variable is going to be selected by a RADIUS and the second variable by means of a SELECT and now I want those two variables to be sent to another file, so that I can upload those two variables to the DB

<form action="cuenta.php" method="post" name="regisConsulta" enctype="multipart/form-data">

<input type="radio" name="cosas_ID" value="<?=$cosa_ID;?>">

<select name="modo_tipo" class="status" >
    <option value="<?=$modo_ID;?>"><?=$tipo;?></option>
</select>

I got a script, but it only sends one variable (LA DEL SELECT), but I can not get it to send the two (radio and select).

$(document).ready(function(){
$('select.status').on('change',function () {
    var decision = $(this).val();
        var id = $('td.myid').html();
    alert(decision);
    $.ajax({    type: "POST",
             url: "guarda_modo.php",
             data: {decision: decision, id: id },
             success: function(msg) {
                 $('#autosavenotify').text(msg);
             }
  })
  });
});
    
asked by RAIC3R 26.06.2018 в 21:33
source

1 answer

0

In your example the sending is done in the change event of the select, and when doing $ (this) .val () that's why it works for the select. If you want to continue along this line, change

var id = $ ('td.myid'). html ();

for

var id = $ ('input [name = things_ID]: checked'). val ();

This takes into account that the radio box is selected, perhaps it is something that you must validate.

It would be best to use form.serialize () to serialize all the fields and their values in an object, and then pass them to the ajax function.

    
answered by 27.06.2018 / 15:51
source