2017-04-10 157 views
0

我該如何檢查收音機盒的值是否爲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'); 

我一定有一個按鈕來選擇subit的價值,或者是有一種方式來獲得的價值,而無需提交按鈕?

這是形式I具有:

  <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

您需要javascript或jquery – clearshot66

+0

@ clearshot66 JavaScript會如何看起來像tho,你能幫我解決嗎? –

+0

我會用jquery快速提交一個答案。給我第二個 – clearshot66

回答

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

+0

是否有可能檢查該值是否等於在PHP內的東西?還是應該包括像你加入的Ajax? –

+0

如果它是一個PHP變量,你必須將它ajax到PHP,因爲JS是前端,PHP是後端 – clearshot66

+0

不,我的意思是我從jquery中檢索到的值。我如何在PHP中使用它?它應該使用ajax嗎? –

相關問題