通过单选按钮检查提交表单
Submit form on radio button check
如果检查了表单radioform
中的单选项,我如何提交表单sAddToBasket
?
<form name="radioform" method="post" action="something1.php">
<input type="radio" onchange="this.form.submit();" class="option--input" id="radio1" name="radio" value="">
<input type="radio" onchange="this.form.submit();" class="option--input" id="radio2" name="radio" value="">
</form>
<form name="sAddToBasket" method="post" action="something2.php">
<input type="hidden" name="option1" value="value1"/>
<input type="hidden" name="option2" value="value2"/>
</form>
我会去掉DOM(你的onchange=...
)中的JS,然后做这样的事情:
$(document).ready( function() {
$("form[name=radioform] input").on("change", function() {
$("form[name=sAddtoBasket").submit();
}
});
你可以尝试一些类似的东西
<form name="radioform" method="post" action="something1.php"> <input type="radio" onchange="document.getElementById('sAddToBasket').submit();" class="option--input" id="radio1" name="radio" value=""> <input type="radio" onchange="document.getElementById('sAddToBasket').submit();" class="option--input" id="radio2" name="radio" value=""> </form>
<form id='sAddToBasket' name="sAddToBasket" method="post" action="something2.php"> <input type="hidden" name="option1" value="value1"/> <input type="hidden" name="option2" value="value2"/>
</form>
onchange您可以调用如下的js函数。
<input type="radio" onchange="formSubmit(this)" class="option--input" id="radio1" name="radio" value="">
<form id="sAddToBasket">
</form>
<script>
function formSubmit(radioObj){
if(radioObj.checked){
document.getElementById("sAddToBasket").submit();
}
}
</script>
只需为单选按钮添加一个类。
<form name="radioform" method="post" action="something1.php">
<input type="radio" class="option--input subForm" id="radio1" name="radio" value="">
<input type="radio" class="option--input subForm" id="radio2" name="radio" value="">
</form>
在脚本上使用这个:
$(function(){
$('.subForm').click(function(){
if($(this).is(":checked")
$('form[name=sAddtoBasket]').submit();
})
})
相关文章:
- Jquery提交表单而不刷新
- 如何在提交表单时将PHP变量传递到Javascript cookie中
- 每次提交表单时都会重新加载网页
- Razor中的自动提交表单
- 使用 JavaScript 自动提交表单
- 点击相同的按钮打开模型,然后提交表单
- 添加和删除隐藏字段数组中的值,而不提交表单
- 使用Ajax提交表单
- jQuery:使用“jQuery验证”后无法提交表单's远程验证
- 如何在不重新加载的情况下提交表单,并使用Node+Express将数据传递回同一页面
- 有登录表单时无法提交表单
- 带有select的jquery提交表单不起作用
- 如何防止回车键提交表单,但仍然允许回车工作
- 使用按钮和单选按钮提交表单,但始终使用相同的值
- 在提交表单之前确定重复值
- 如何创建动态ajax提交表单
- HTML提交表单,同时包含空字段检查和按钮隐藏
- 如何使用jQueryAjax使用动态html输入texbox提交表单
- 当触发下拉列表的onchange事件时,使用JavaScript提交表单
- 提交表单后,Watir文本框输入未持续(重置为以前的文本框输入)