views:

91

answers:

2

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?

+1  A: 

$("[name='vote']:selected").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){
  });
});
mr.moses
it POSTs undefined.
amit
oops, should be :checked not :selected. I fixed the sample. It will be undefined if no radio button is selected.
mr.moses
A: 

Jquery serialize is the best way to do this kind of things: http://docs.jquery.com/Ajax/serialize

$("#submit_js").click(function() {
    $.post(
    "user_submit.php", 
    $("form").serialize(), 
    function(data){
    });
});
AlfaTeK
That's if you want ALL the input elements from the form
AUSteve