如何在javascript的循环中从表单中选择特定的隐藏元素
how to select specfic hidden element from a form in a loop in javascript?
所以基本上,我的循环输出四次下面的html,在$show_id中有不同的值。当调用函数时,Everyform返回第一个表单的$show_id值,而不是表单的值。如何解决这个问题?
我javascript <script type="text/javascript" >
function addScore() {
var show_id = $('#show_id').val();
var user_id = $('#user_id').val();
var score = $('input[name=tvshowrating]:checked').val();
if(score=='')
{
alert('PleaseEnter A Score');
}
else
{
$("#flash").show();
$("#flash").html('<img src="ajax-loader.gif" />Loading Score...');
$.ajax({
type: "POST",
url: "showscoreajax.php",
data:{
"show_id" : show_id,
"user_id" : user_id,
"score" : score //we are passing the name value in URL
},
cache: false,
success: function(data){
$("#flash").html('Added');
}
});
}
return false;
};
</script>
myhtml
<div id="flash"></div>
<form id="form3B">
<div class="your-score">
<div class="">Your Score</div>
<input class="hover-star" type="radio" name="tvshowrating" value="1" title="1"/>
<input class="hover-star" type="radio" name="tvshowrating" value="2" title="2"/>
<input class="hover-star" type="radio" name="tvshowrating" value="3" title="3"/>
<input class="hover-star" type="radio" name="tvshowrating" value="4" title="4"/>
<input class="hover-star" type="radio" name="tvshowrating" value="5" title="5"/>
<input class="hover-star" type="radio" name="tvshowrating" value="6" title="6"/>
<input class="hover-star" type="radio" name="tvshowrating" value="7" title="7"/>
<input class="hover-star" type="radio" name="tvshowrating" value="8" title="8"/>
<input class="hover-star" type="radio" name="tvshowrating" value="9" title="9"/>
<input class="hover-star" type="radio" name="tvshowrating" value="10" title="10"/>
<input type="hidden" id="show_id" value="<?php echo $row[0]; ?>" />
<input type="hidden" id="user_id" value="<?php echo $user_id ?>" />
<span id="hover-test" style="margin:0 0 0 20px;"></span>
<input id="submitscore" type="submit" value="Submit scores!" onclick="addScore()" />
</div>
</form>
</div>
</div>
这是因为你不能有重复的id,不像重复的类,你需要为每个表单不同的id。像这样
<input type="hidden" id="show_id-form3B" value="<?php echo $row[0]; ?>" />
那么你就有可能得到每个不同形式的唯一值。像这样的
function addScore(formId) {
var show_id = $('#show_id-'+formId).val();
var user_id = $('#user_id-'+formId).val();
//add your code
}
相关文章:
- 基于其他下拉菜单选择隐藏/显示下拉菜单
- 货到付款选择隐藏/显示付款方式
- 根据下拉选择隐藏四个输入框
- 如何根据下拉菜单选择隐藏/显示文本框
- 如何根据下拉列表中的选择隐藏表格行
- 根据多个选择隐藏选择选项
- 如何根据选择隐藏谷歌图表工具提示操作
- 但是,根据下拉选择隐藏和显示输入文本
- 通过复选框选择隐藏动态谷歌地图标记
- 尝试使用jQuery在父DOM中选择隐藏字段
- 启动-选择隐藏事件未触发
- PHP - WebCalendar -基于下拉列表选择隐藏字段
- 引导下拉隐藏点击选择隐藏下拉
- 更改html列表以选择隐藏的输入类型
- 如何用jQuery选择隐藏表格中的行
- 根据单选按钮选择隐藏OK按钮
- 选择隐藏和显示问题:多于两个元素
- 根据下拉列表中的选择隐藏和显示面板
- 选项列表中选择隐藏和显示
- 按Id选择隐藏的表单元素