tags:

views:

27

answers:

1

Hey! 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
    $price = 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!

A: 

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.

Aaron Hathaway
Ok. I forgot to change this value when I copied it. I have corrected it. In Firefox it still doesn't work.
Daniel
Is JavaScript enabled? Have you tried doing a simple alert?
Aaron Hathaway
Yes. In Safari it return the value"on" for p1 and "" for p2 if p1 is selected and"" for p1 and "on" for p2 if p2 is selected.In Firefox is return the value "on" for p1 and "on" for p2 if p1 is selected or p2. They always both have the value "on" in Firefox.
Daniel
Can I do dynamic price calculation with an existing framework?
Daniel