可能重複:
How can I get which radio is selected via jQuery?無線電只有在通過第一個值
我試圖把用戶的評級系統我的網站,但只有第一個值被傳遞,所以在表格中,評分欄總是一個。自從我與無線電合作以來,這已經有一段時間了。
這是我的。
<form id="add-rateing">
<input type="radio" name="MOVIE_RATING" value="1" > 1
<input type="radio" name="MOVIE_RATING" value="2" > 2
<input type="radio" name="MOVIE_RATING" value="3" checked="yes"> 3
<input type="radio" name="MOVIE_RATING" value="4" > 4
<input type="radio" name="MOVIE_RATING" value="5" > 5 <br>
<input type="hidden" name="MOVIE_ID" value="<?php echo $id; ?>">
<input type="hidden" name="MOVIE_TITLE" value="<?php echo $title; ?>">
<input type="hidden" name="USER_ID" value="<?php echo $loggedinusername; ?>">
<input type="submit" value="I Drank To The Credits" onclick="$('#add-rateing').hide('fast')">
</form>
<script type="text/javascript">
$("#add-rateing").submit(function(event){
event.preventDefault()
addrateing();
});
function addrateing()
{
var movie_rating_s = $("#add-rateing [name='MOVIE_RATING']").val();
var movie_id_s = $("#add-rateing [name='MOVIE_ID']").val();
var movie_title_s = $("#add-rateing [name='MOVIE_TITLE']").val();
var user_id_s = $("#add-rateing [name='USER_ID']").val();
var errors = '';
$.ajax({
type : "POST",
url : "movie_watched.php",
data : { rating: movie_rating_s,
movie : movie_id_s,
title: movie_title_s,
user : user_id_s, },
cache : false, timeout: 10000,
success : function() {
alert("You have played <?php echo $title; ?> ");
},
error : function() {
alert("there is a problom");
},
complete : function() {
}
});
};
</script>
'變種movie_rating_s = $(「#加-rateing [name ='MOVIE_RATING'] [checked ='yes'「)。val();' – Musa 2012-04-25 21:40:17
考慮使用[jquery form插件](http://jquery.malsup.com/form/)。它負責正確地序列化你的表單。 – ThiefMaster 2012-04-25 21:42:02
您應該考慮正確拼寫「評分」。它被正確拼寫爲「評級」。 – 2012-04-25 21:42:48