I am trying to do the temperature converter in PHP without reloading the page using the jquery, but having problem......
This is the Index.php page
Jqeury function for printing data without reloading..
function SubmitFormData(){
var first = $("#valueConvert").val();
var operator = $("#convertType").val();
$.post("temperature_calculate.php",
{
first:first,
operator: operator
},
function(data){
$('#results').html(data);
$('#formcal')[0].reset();
});
}
HTML code:
<form name="tempConvert" id="formcal" method="POST">
<input type="text" name="valueConvert" id="valueConvert" size="15">
Convert to:
<select name="convertType" id="convertType" size="1">
<option disabled> Select a measurement type</option>
<option value="celsius">Celsius</option>
<option value="fahrenheit">Fahrenheit</option>
</select>
<td><input type="submit" name="btnConvert" id="btnConvert" value="Convert">
</form>
<div id="results">
</div>
And this is the php code that process the value:
<?php
function tempConvert($valueConvert, $convertType) {
if($convertType == "fahrenheit"){
$conversion = ((9/5) * $valueConvert) + (32);
} else if ($convertType == "celsius"){
$conversion = ($valueConvert - 32) * (5/9);
}
return $conversion;
}
$valueConvert = $_POST['valueConvert'];
$convertType = $_POST['convertType'];
$conversion = tempConvert($valueConvert, $convertType);
echo " $conversion.";
?>
Aucun commentaire:
Enregistrer un commentaire