amit amit -4 years ago 86
Javascript Question

how to POST radio button values through jquery

i have this example code:

while ($row = mysql_fetch_object($result1)) {
echo '<input type="radio" name="vote" value='.$row->avalue.'/>&nbsp;';
echo '<label >'.$row->atitle.'</label><br>';
}


this displays 4 radio buttons alongwith their labels.
now I am using the following jquery function to POST.

$("#submit_js").click(function() {
$.post(
"user_submit.php",
{//how to POST data?},
function(data){
});
});


I want to post the value associated with the radio button. but how do i select the value?
how do i determine what radio button is selected and POST it?

Answer Source

$("[name='vote']:checked").val() will get you the value of the selected radio button.

$("#submit_js").click(function() {
  $.post(
  "user_submit.php", 
  {vote: $("[name='vote']:checked").val()}, 
  function(data){
  });
});
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download