[英]How can i check if the radio button is checked or not without a submit button?
我如何檢查單選框的值是Pearson還是Euclidean。 所以我現在是這樣的:
if ($_SERVER['REQUEST_METHOD'] === 'POST')
{
if($_POST['radio'] == 'Euclidean'){
$get_recommendations = get_recommendations($new_videos,$user_data['username'], $sim_score='sim_euclidean');
}
}
// as default i want the pearson method to be used
else{
$get_recommendations = get_recommendations($new_videos,$user_data['username'], $sim_score='sim_pearson');
我是否需要一個按鈕來替換所選的值,或者是否有一種無需提交按鈕即可獲取值的方法?
這是我的表格:
<form action="" method="post">
<div class="control-group">
<h1 style="font-size:22px;">Choose method to recommend with:</h1>
<label class="control control--radio">Pearson
<input type="radio" name="radio" value="Pearson" checked="checked"/>
<div class="control__indicator"></div>
</label>
<label class="control control--radio">Euclidean
<input type="radio" name="radio" value="Euclidean"/>
<div class="control__indicator"></div>
</label>
</div>
</form>
使用jquery時,請給radio一個radio的類或ID:
$(document).ready(function()){
$('input:radio[name="radio"]').change(function()){
var value = $('form input[type=radio]:checked').val(); // Gets val of checked on change event
// code to manipulate it, can also be sent to a php file via ajax if you need it that way
}
}
鏈接,將圍繞jquery的變量傳遞給php將jQuery值傳遞給PHP
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.