How to retrieve $('input:radio[name=vote]:checked').val()
Hello,
This is my issue:
I've got a simple poll
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<link rel="stylesheet" type="text/css" href="style.css?" />
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#poll #submit").click(function () {
$("#poll").html('<img src="ajax-loader.gif" />');
$.ajax({
type: "GET",
data: "data=" + $('input:radio[name=vote]:checked').val(),
url: "response.php",
success: function(msg){
$("#poll").html(msg)
}
});
});
});
</script>
</head>
<body>
<div id="poll">
<h4>Here comes the question...?</h4>
<div class="label">
<input type="radio" name="vote" value="0" />
<label for="vote">Answer 1:</label>
</div>
<br />
<div class="label">
<input type="radio" name="vote" value="1" />
<label for="vote">Answer 2:</label>
</div>
<input type="button" name="submit" value="Vote" id="submit" />
</div><!-- end poll -->
</body></html>
response.php
- <?php
$sampleData = $_GET['data'];
echo $sampleData; ?>
but at the and I get "undefined" as returned value, instead of values of radio buttons "0" or "1" which I should.
I found $('input:radio[name=vote]:checked').val() should be the correct code to retrieve the values of radio inputs, but in my case doesn't work ,or I am doing something wrong?