简体   繁体   English

提交单选按钮检查表格

[英]Submit form on radio button check

How can I Submit the form sAddToBasket if a radio inside the form radioform gets checked ? 如果检查了表单无线电表单内的单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>

I would get rid of the JS in the DOM (your onchange=... ) and do something like this: 我将摆脱DOM(您的onchange=... )中的JS,然后执行以下操作:

$(document).ready( function() {
  $("form[name=radioform] input").on("change", function() {
    $("form[name=sAddtoBasket").submit();
  }
});

You can try some thing like this 你可以尝试这样的事情

<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 you can call a js function like below. 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>

just add a class to the radio buttons. 只需在单选按钮上添加一个类即可。

<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>

and on the script use this: 并在脚本上使用以下命令:

 $(function(){
$('.subForm').click(function(){
if($(this).is(":checked")
$('form[name=sAddtoBasket]').submit();

})
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM