2016-04-17 41 views
0

如何檢查表格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> 

回答

1

我會擺脫JS的DOM(你onchange=...),做這樣的事情:

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

您可以嘗試這樣的事

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

平變化,你可以調用一個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> 
0

只需添加一個類的單選按鈕。

<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(); 

}) 
})