如何查看收音机盒的价值,无论是Pearson还是欧几里德。 所以我现在拥有的是:
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>
答案 0 :(得分:1)
使用jquery,为无线电提供一个类或无线电的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的链接 Passing jQuery Value to PHP