Reputation: 85
How can i check the value of the radio box whether its Pearson or euclidean. So what i have now is this:
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');
Do i have to have a button to subit the value chosen, or is there a way to get the value without having a submit button?
This is the form i have:
<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>
Upvotes: 0
Views: 434
Reputation: 2302
With jquery, give radio a class or id of radio for example:
$(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
}
}
Link for passing variables around jquery to php Passing jQuery Value to PHP
Upvotes: 1