I am building a pizza ordering form that calculates form fields depends on user choices and returns the total. The first input will be the currency drop down, once user selects currency, it should pass value to PHP variable $currency (so that it will calculate the exchange rate) without the need to submit the form of course.
I have seen a lot of similar codes, but got confused, I know I should be using JavaScript / Ajax, but my knowledge is weak in that.
Can you please paste a simple code that will pass the $currency value to PHP?
<html>
<head>
<title></title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
jQuery(function($){
$("#currency").change(function(){
var selected_value = $(this).val();
/*AJAX CODE HERE TO PASS VALUE OF DROP DOWN TO PHP*/
$.post("CurrencyCalculator.php", $("#currency").serialize()); //this is the problematic part: it needs to pass the $currency variable
})
})
</script>
</head>
<body>
Select any one:
<select id="currency" name="currency" onchange="selectDropdown()">
<option value="EUR" >Euro</option>
<option value="USD" >US Dollar</option>
<option value="GBP" >British Pound</option>
</select>
</body>
</html>