So, basically i'm trying to create a simple usd to pounds converter using php and ajax. I know it'd be much easier with jQuery but this is an assignment and jQuery isn't allowed. Below is the code i'm working on, but when I run it gives me "Please make sure entry is a valid number." even when i'm definitely putting in a numeric value. I've been searching for hours to try to find out how to fix this code, so i'm hoping someone here can give me some insight.
HTML
<form method="get" action="">
<label for="damount">Dollars to Convert:</label>
<input type="text" name="damount" id="damount">
<div>
<input type="button"value="go" onclick="submitForm();">
</div>
<p id="results"></p>
</div>
</form>
AJAX
var http2 = createRequestObject();
function createRequestObject() {
var ro;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
ro = new ActiveXObject("Microsoft.XMLHTTP");
}else{
ro = new XMLHttpRequest();
}
return ro;
}
function submitForm() {
http2.open('get', 'calculations.php');
http2.onreadystatechange = toCalc;
http2.send(null);
}
function toCalc() {
if(http2.readyState == 4){
document.getElementById("results").innerHTML = http2.responseText;
}
}
PHP
if (isset($_REQUEST['damount']) && is_Numeric($amount))
{
$rate = 0.80;
$amount = $_REQUEST['damount'];
$money = $rate * $amount;
echo '£' . number_format($money, 2, '.', '');
}
else
{
echo "Please make sure entry is a valid number.";
}
I'm still really new to aJax, so any help would be appreciated.
http2.open('get', 'calculations.php');tohttp2.open('get', 'calculations.php?damount='+document.getElementById("damount").value());