paypal javascript drop下拉菜单复选框

时间:2013-07-22 16:51:47

标签: javascript paypal

如何使用相同的算法或更好的方法将此PHP函数转换为JavaScript?

error_reporting( E_ALL ^ E_NOTICE );
if($_GET['text008']=="1br")
{   $typeservice=119;
    if(isset($_GET['extras']))
    foreach ($_GET['extras'] as $k){   
    $total +=$k;
    } 
    echo "Service: $" . $typeservice . "<br/>" . "Extra Fees: $" .$total . "<br/>";

    echo "Service w/ Extra Fee: $" . $balyo=$typeservice + $total;

    if(isset($_GET['freq']))
    {
        if($_GET['freq']=="O")
        {
            echo "<br/>Once";
            echo "<br/>Discount: $" . ($balyo * .15);
            echo "<br/> Total: $" . $lahat;     
        }
        if($_GET['freq']=="M")
        {   
            echo "<br/>Monthly";    
            $lahat = $balyo - ($balyo * .10);
            echo "<br/>Discount:$ " . ($balyo * .15);
            echo "<br/> Total: $" . $lahat;             
        }       
        if($_GET['freq']=="BW")
        {
            echo "<br/>Bi-Weekly";  
            $lahat = $balyo - ($balyo * .15);
            echo "<br/>Discount: $" . ($balyo * .15);
            echo "<br/> Total: $" . $lahat;             
        }
        if($_GET['freq']=="W")
        {
            echo "<br/>Weekly"; 
            $lahat = $balyo - ($balyo * .15);
            echo "<br/>Discount: $" . ($balyo * .15);
            echo "<br/> Total: $" . $lahat;             
        }       
    }

}



if($_GET['text008']=="2br")
{
    $typeservice=139;
    if(isset($_GET['extras']))
    foreach ($_GET['extras'] as $k){   
    $total +=$k;
    } 
    echo "Service: $" . $typeservice . "<br/>" . "Extra Fees: $" .$total . "<br/>";

    echo "Service w/ Extra Fee: $" . $balyo=$typeservice + $total;

    if(isset($_GET['freq']))
    {
        if($_GET['freq']=="O")
        {
            echo "<br/>Once";
            echo "<br/>Discount: $" . ($balyo * .15);
            echo "<br/> Total: $" . $lahat;     
        }
        if($_GET['freq']=="M")
        {   
            echo "<br/>Monthly";    
            $lahat = $balyo - ($balyo * .10);
            echo "<br/>Discount:$ " . ($balyo * .15);
            echo "<br/> Total: $" . $lahat;             
        }       
        if($_GET['freq']=="BW")
        {
            echo "<br/>Bi-Weekly";  
            $lahat = $balyo - ($balyo * .15);
            echo "<br/>Discount: $" . ($balyo * .15);
            echo "<br/> Total: $" . $lahat;             
        }
        if($_GET['freq']=="W")
        {
            echo "<br/>Weekly"; 
            $lahat = $balyo - ($balyo * .15);
            echo "<br/>Discount: $" . ($balyo * .15);
            echo "<br/> Total: $" . $lahat;             
        }       
    }

}
if($_GET['text008']=="3br")
{
    $typeservice=159;
    if(isset($_GET['extras']))
    foreach ($_GET['extras'] as $k){   
    $total +=$k;
    } 
    echo "Service: $" . $typeservice . "<br/>" . "Extra Fees: $" .$total . "<br/>";

    echo "Service w/ Extra Fee: $" . $balyo=$typeservice + $total;

    if(isset($_GET['freq']))
    {
        if($_GET['freq']=="O")
        {
            echo "<br/>Once";
            echo "<br/>Discount: $" . ($balyo * .15);
            echo "<br/> Total: $" . $lahat;     
        }
        if($_GET['freq']=="M")
        {   
            echo "<br/>Monthly";    
            $lahat = $balyo - ($balyo * .10);
            echo "<br/>Discount:$ " . ($balyo * .15);
            echo "<br/> Total: $" . $lahat;             
        }       
        if($_GET['freq']=="BW")
        {
            echo "<br/>Bi-Weekly";  
            $lahat = $balyo - ($balyo * .15);
            echo "<br/>Discount: $" . ($balyo * .15);
            echo "<br/> Total: $" . $lahat;             
        }
        if($_GET['freq']=="W")
        {
            echo "<br/>Weekly"; 
            $lahat = $balyo - ($balyo * .15);
            echo "<br/>Discount: $" . ($balyo * .15);
            echo "<br/> Total: $" . $lahat;             
        }       
    }

}
if($_GET['text008']=="4br")
{
    $typeservice=189;
    if(isset($_GET['extras']))
    foreach ($_GET['extras'] as $k){   
    $total +=$k;
    } 
    echo "Service: $" . $typeservice . "<br/>" . "Extra Fees: $" .$total . "<br/>";

    echo "Service w/ Extra Fee: $" . $balyo=$typeservice + $total;

    if(isset($_GET['freq']))
    {
        if($_GET['freq']=="O")
        {
            echo "<br/>Once";
            echo "<br/>Discount: $" . ($balyo * .15);
            echo "<br/> Total: $" . $lahat;     
        }
        if($_GET['freq']=="M")
        {   
            echo "<br/>Monthly";    
            $lahat = $balyo - ($balyo * .10);
            echo "<br/>Discount:$ " . ($balyo * .15);
            echo "<br/> Total: $" . $lahat;             
        }       
        if($_GET['freq']=="BW")
        {
            echo "<br/>Bi-Weekly";  
            $lahat = $balyo - ($balyo * .15);
            echo "<br/>Discount: $" . ($balyo * .15);
            echo "<br/> Total: $" . $lahat;             
        }
        if($_GET['freq']=="W")
        {
            echo "<br/>Weekly"; 
            $lahat = $balyo - ($balyo * .15);
            echo "<br/>Discount: $" . ($balyo * .15);
            echo "<br/> Total: $" . $lahat;             
        }       
    }

}
if($_GET['text008']=="5br")
{
    $typeservice=219;
        if(isset($_GET['extras']))
    foreach ($_GET['extras'] as $k){   
    $total +=$k;
    } 
    echo "Service: $" . $typeservice . "<br/>" . "Extra Fees: $" .$total . "<br/>";

    echo "Service w/ Extra Fee: $" . $balyo=$typeservice + $total;

    if(isset($_GET['freq']))
    {
        if($_GET['freq']=="O")
        {
            echo "<br/>Once";
            echo "<br/>Discount: $" . ($balyo * .15);
            echo "<br/> Total: $" . $lahat;     
        }
        if($_GET['freq']=="M")
        {   
            echo "<br/>Monthly";    
            $lahat = $balyo - ($balyo * .10);
            echo "<br/>Discount:$ " . ($balyo * .15);
            echo "<br/> Total: $" . $lahat;             
        }       
        if($_GET['freq']=="BW")
        {
            echo "<br/>Bi-Weekly";  
            $lahat = $balyo - ($balyo * .15);
            echo "<br/>Discount: $" . ($balyo * .15);
            echo "<br/> Total: $" . $lahat;             
        }
        if($_GET['freq']=="W")
        {
            echo "<br/>Weekly"; 
            $lahat = $balyo - ($balyo * .15);
            echo "<br/>Discount: $" . ($balyo * .15);
            echo "<br/> Total: $" . $lahat;             
        }       
    }

}
if($_GET['text008']=="6br")
{
    $typeservice=249;
    if(isset($_GET['extras']))
    foreach ($_GET['extras'] as $k){   
    $total +=$k;
    } 
    echo "Service: $" . $typeservice . "<br/>" . "Extra Fees: $" .$total . "<br/>";

    echo "Service w/ Extra Fee: $" . $balyo=$typeservice + $total;

    if(isset($_GET['freq']))
    {
        if($_GET['freq']=="O")
        {
            echo "<br/>Once";
            echo "<br/>Discount: $" . ($balyo * .15);
            echo "<br/> Total: $" . $lahat;     
        }
        if($_GET['freq']=="M")
        {   
            echo "<br/>Monthly";    
            $lahat = $balyo - ($balyo * .10);
            echo "<br/>Discount:$ " . ($balyo * .15);
            echo "<br/> Total: $" . $lahat;             
        }       
        if($_GET['freq']=="BW")
        {
            echo "<br/>Bi-Weekly";  
            $lahat = $balyo - ($balyo * .15);
            echo "<br/>Discount: $" . ($balyo * .15);
            echo "<br/> Total: $" . $lahat;             
        }
        if($_GET['freq']=="W")
        {
            echo "<br/>Weekly"; 
            $lahat = $balyo - ($balyo * .15);
            echo "<br/>Discount: $" . ($balyo * .15);
            echo "<br/> Total: $" . $lahat;             
        }       
    }
}

1 个答案:

答案 0 :(得分:0)

我在Facebook上回复了一个更新的jsFiddle,但我想我会在这里发布,以防万一。这是一个jsFiddle设置,结合if语句中缺少大括号,并将金额设置为整数而不是字符串。

function CalculateOrder(form)
{   
    //sample lang to sir ng javascript pero ito mismo na yung code.
    //naka comment sa html ung code sa php 
    if(form.text008.value == "1br")
    {
        form.amount.value ="119.00";
    }

    if(form.text008.value == "1br" && form.extrass.checked ==true)
    {
        form.amount.value = "139";
    }
}