form radio box ajax value
I programmed a form which dynamically calculates the price. You can select between 2 packages.
<input type="radio" id="p1" onclick="doWork();" name="package"/>
<input type="radio" id="p2" onclick="doWork();" name="package"/>
In Ajax I send the value to a php file.
function doWork(){
httpObject = getHTTPObject();
if (httpObject != null) {
var url = "price.php?p1=" + document.getElementById('p1').value + "&p2=" + document.getElementById('p2').value;
httpObject.open("GET", url, true);
httpObject.send(null);
httpObject.onreadystatechange = setOutput;
}
}
Inside the php file I do
<?php
$pri开发者_JS百科ce = 0;
if ($_GET['p1'] == 'on') $price += 1;
if ($_GET['p2'] == 'on') $price += 2;
echo $price."$";
?>
In Safari it shows the right price. But in Firefox I always get the price 3. I doesn't change if I choose 1 or 2 it always is the sum of 1 and 2.
What do I have to change?
Thanks!
When you fetch the get variables in your PHP page you are using 'p1' and 'p2'. It looks like the url of your Ajax is being set to price.php?pbasic=" + document.getElementById('p1').value + "&ppro=" + document.getElementById('p2').value
so it appears there's some name mix-ups.
精彩评论