I’m not sure if I am making this more complex then what it is… What I want to do: depending on which button the user presses $price should be calculated and displayed without the page beeing reloaded. The $price variable gets its data from a database. I cannot get this to work so if someone could help me would be fantastic, thanks linda
my form
<form id="f1" method="POST">
<label for="r1">Exkl. moms</label><input type="radio" name="radio" value="exkl" checked="checked" id="r1"/>
<label for="r2">Inkl. moms</label><input type="radio" name="radio" value="inkl" id="r2"/>
</form>
<div id="results"></div>
<?php
if(($_SESSION['user_info']['moms'])=="inkl"){
$price*1.25;
}
?>
jquery
function showValues() {
var str = $("#f1").serialize();
$.ajax({
type: "POST",
url: "momsTest2.php",
data: str,
success: function(html){
$('#results').html(html);
}
});
}
$(":radio").change(showValues);
showValues();
momsTest2.php page
session_start();
$_SESSION['user_info']['moms'] = $_POST['radio'];
Does it need to be done server side? Otherwise, what you can do is first load the price from the database and save it to a javascript variable, then perform the calculations client side in javascript instead of using ajax to process the calculation server side.