I would like to know how to pass the value of a radius via post with ajax or jquery

1

I needed help to pass any value of one of these inputs via Ajax or jQuery:

<input type="radio" id="valorum" name="valor" value="38,70" ></br>
<input type="radio" id="valordois" name="valor" value="71,40" ></br>
<input type="radio" id="valortres" name="valor" value="118,80" ><br><br>


$.ajax({
  method: "GET",
  url: "test.js",
  dataType: "script"
});

How would I spend one of these values within this Ajax? Or is there no way, or is there another method of doing this?

    
asked by anonymous 30.10.2017 / 21:02

2 answers

1

You can use this line to get the value of the button that is selected, replace the myForm with the ID of your form

Example of how the code should be

var campoRadio =  $('input[name=valor]:checked', '#myForm').val();
$.ajax({
   method: "GET",
   data: { campoRadio: campoRadio },
   url: "test.js",
   dataType: "script"
});

Ideally, if you could use post instead of get

    
30.10.2017 / 21:24
1

Get the values for the id.               

<script>
var value = $("#valorum").val();
$.ajax({
        method: "GET",
        data: { suaVariavelDoServidor: value },
        url: "test.js",
        dataType: "script"
});
</script>

If you want to send all values as array:

var values = []
$("input").each(function(){
     values.push(this.value);   
});
$.ajax({
        method: "GET",
        data: { suaVariavelDoServidor: values },
        url: "test.js",
        dataType: "script"
});
    
30.10.2017 / 21:19