Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从javascript函数的值计算Vat_Php_Calculator - Fatal编程技术网

Php 从javascript函数的值计算Vat

Php 从javascript函数的值计算Vat,php,calculator,Php,Calculator,大家好我需要帮助 然后我有一个表单,通过javascript函数我计算一个产品的总数,然后发送邮件 现在我想计算这个值的增值税,但它不起作用,我理解为什么,也许,给我的值是一个值而不是一个数字,例如,他给我100欧元。。不是100,然后我想知道,是否有一个系统将数字提取到那个值,然后让他计算增值税 谢谢你我想这就是你需要的 试试看。此函数返回一个字符串数组 $valueWithCurrency = "100 Euros"; $extractedValue = explode(' ', $valu

大家好我需要帮助 然后我有一个表单,通过javascript函数我计算一个产品的总数,然后发送邮件 现在我想计算这个值的增值税,但它不起作用,我理解为什么,也许,给我的值是一个值而不是一个数字,例如,他给我100欧元。。不是100,然后我想知道,是否有一个系统将数字提取到那个值,然后让他计算增值税
谢谢你我想这就是你需要的

试试看。此函数返回一个字符串数组

$valueWithCurrency = "100 Euros";
$extractedValue = explode(' ', $valueWithCurrency); //space as a delimiter in first argument
echo $extractedValue[0]; //Here you go. "100"
echo $extractedValue[1]; //this contains "Euros"
对不起。 这是我购买的插件代码

(function($) {

 $.fn.SimplePriceCalc= function (options) {

 // Default options for text

    var settings = $.extend({       
    totallabel: "Total:",
    detailslabel: "Details:",
    currency:"$"        
    }, options );

// Initialize Variables

var total=0;
var child=this.find('*'); 
var formdropdowns=this.find('select');
this.addClass("simple-price-calc"); 
InitialUpdate();    

  // Change select data cost on each change to current selected value

formdropdowns.change( function() {
    if($(this).attr('multiple')) {
        var selectedOptions = $(this).find(':selected');
        var selectedOptionstotal=0;
        if (selectedOptions != '')
        {
            selectedOptions.each( function() {
                selectedOptionstotal += $(this).data('price');              
            });
        }
        $(this).attr('data-total',selectedOptionstotal);
    }
    else{       
    var selectedOption = $(this).find(':selected');
    if($(this).data('mult') >= 0) 
          $("#simple-price-total label").attr('data-mult',selectedOption.val()); 
    else 
        $(this).attr('data-total',selectedOption.data('price')) ;                   
    }       
    UpdateTotal();
});

//Update total when user inputs or changes data from input box

$(".simple-price-calc input[type=text]").change( function() {

    if($(this).attr('data-price') || $(this).attr('data-mult')) {

    var userinput= $(this).val();
    if($.isNumeric(userinput)) { var usernumber = parseFloat(userinput);} else if(userinput != '') { alert('Please enter a valid number'); var usernumber = 1; } else { usernumber = 1; }
    var multiple=parseFloat($(this).data('mult')) || 0;
    var pricecost=parseFloat($(this).data('price')) || 0;
    var percentage=$(this).data('prcnt') || 1;

    if($.isNumeric(pricecost) && pricecost !=0) {
        var updpricecost=pricecost * usernumber;
        $(this).attr('data-total', updpricecost);
    }

    if(multiple && multiple !=0) {      
        $("#simple-price-total label").attr('data-mult',usernumber);
    }

    }

    UpdateTotal();

});

$(".simple-price-calc input[type=checkbox]").change( function() {

    if($(this).is(':checked')) {
        var checkboxval= $(this).val();
        if($.isNumeric(checkboxval)) {              
            $(this).attr('data-total', checkboxval);                
        }
        else {
            $(this).attr('data-total', 0);
        }
    }                   
    else {
        $(this).attr('data-total', 0);
    }       

UpdateTotal();

});

    $(".simple-price-calc input[type=radio]").change( function() {
        $(".simple-price-calc input[type=radio]").each( function() {
            if($(this).is(':checked')) {
                var radioval= $(this).val();
                if($.isNumeric(radioval)) {             
                    $(this).attr('data-total', radioval);
                }
                else {
                    $(this).attr('data-total', 0);
                }
            }                   
            else {
                $(this).attr('data-total', 0);
            }       
        }); 
    UpdateTotal();

    });



//Initialize all fields if data is there

function InitialUpdate() {

    formdropdowns.each( function() {
     if($(this).attr('multiple')) {
        var selectedOptions = $(this).find(':selected');
        var selectedOptionstotal=0;
        if (selectedOptions != '')
        {
            selectedOptions.each( function() {
                selectedOptionstotal += $(this).data('price');              
            });
        }
        $(this).attr('data-total',selectedOptionstotal);
     }
    else{       
    var selectedOption = $(this).find(':selected');
    $(this).attr('data-total',selectedOption.data('price')) ;                   
     }      
    });

    //Update total when user inputs or changes data from input box

    $(".simple-price-calc input[type=text]").each( function() {

    if($(this).attr('data-price') || $(this).attr('data-mult')) {

        var userinput= $(this).val();
        if($.isNumeric(userinput)) { var usernumber = parseFloat(userinput);} else if(userinput != '') { alert('Please enter a valid number'); var usernumber = 1;} else { usernumber = 1; }
        var multiple=parseFloat($(this).data('mult')) || 0;
        var pricecost=parseFloat($(this).data('price')) || 0;
        var percentage=$(this).data('prcnt') || 1;

        if($.isNumeric(pricecost) && pricecost !=0) {
            var updpricecost=pricecost * usernumber;
            $(this).attr('data-total', updpricecost);
        }

        if(multiple && multiple !=0) {      
            $("#simple-price-total label").attr('data-mult',usernumber);
        }           

        }

    });

    $(".simple-price-calc input[type=checkbox]").each( function() {

        if($(this).is(':checked')) {
            var checkboxval= $(this).val();
            if($.isNumeric(checkboxval)) {              
                $(this).attr('data-total', checkboxval);
            }
            else {
                $(this).attr('data-total', 0);
            }
        }                   
        else {
            $(this).attr('data-total', 0);
        }                   

    });


        $(".simple-price-calc input[type=radio]").each( function() {
            if($(this).is(':checked')) {
                var radioval= $(this).val();
                if($.isNumeric(radioval)) {             
                    $(this).attr('data-total', radioval);
                }
                else {
                    $(this).attr('data-total', 0);
                }
            }                   
            else {
                $(this).attr('data-total', 0);
            }       
        });     
        UpdateTotal();

}

    //Change value of total field by adding all data totals in form

function UpdateTotal() {

    total=0;
    totalmult=$(".simple-price-calc #simple-price-total label").attr("data-mult");

    //For each input with data-merge attr, take merge ids value and multiply by current data-price  
    $("input[data-merge]").each(function(){
        var ids=$(this).data('merge');
        var ids=ids.split(',');
        var arraytotals=1;          
        $.each(ids, function(key,value) {
            var inputid =$("#"+value);              
            if( (inputid.attr('type') == 'checkbox' || inputid.attr('type') == 'radio')  && inputid.is(':checked') )
                arraytotals*=$("#"+value).val(); 
            else if (inputid.attr('type') == 'text') 
                arraytotals*=$("#"+value).val();
            else if (inputid.prop('nodeName') == "SELECT")
                arraytotals*=$("#"+value).attr('data-total');
            });
        var idtotal=arraytotals;
        if($.isNumeric(idtotal)) {                  
            var pricecost=parseFloat($(this).data('price')) || 0;
            $(this).val(idtotal);
            var updpricecost= pricecost * parseFloat($(this).val());
            $(this).attr('data-total',updpricecost);                        
        }
    });

    child.each(function () {
        itemcost=   $(this).attr("data-total") || 0;
        total += parseFloat(itemcost);
    });         

    if(totalmult) { total = total * parseFloat(totalmult); }
    $(".simple-price-calc #simple-price-total label").html(settings.currency+$.number(total,2));        

    setTimeout(function() {
    UpdateDescriptions();
    }, 100);


}

//Update Field Labels and Pricing   

    function UpdateDescriptions() {             

    var selectedformvalues= [];
    var currtag='';

    $(".simple-price-calc").find('*').each( function () {

    currtag=$(this).prop('tagName');

    if(currtag == "SELECT") { 
        if($(this).attr('multiple')) {
        var selectedOptions = $(this).find(':selected');            
        if (selectedOptions != '')
        {
            selectedOptions.each( function() {
                var optionlabel= $(this).data('label') || ''; 
                var optionprice = $(this).data('price');
                if(optionlabel != '') {
                        selectedformvalues.push(optionlabel + ": " + settings.currency + optionprice);              
                    }
            });
        }

    }
    else{       
    var selectedOption = $(this).find(':selected');
    if (selectedOption != '')
        {
                var optionlabel= selectedOption.data('label') || '';
                var optionprice = selectedOption.data('price');
                 if(optionlabel != '') {
                        selectedformvalues.push(optionlabel +": " + settings.currency + optionprice);               
                    }

         }      
     }

    } // End of Form dropdown

    if(currtag == "INPUT" && $(this).attr('type') == "text") 
    {
            if($(this).attr('data-price') || $(this).attr('data-mult')) {

        var userinput= $(this).val();           
        if($.isNumeric(userinput)) { var usernumber = parseFloat(userinput);}  else { var usernumber = 1; }         
        var pricecost=parseFloat($(this).data('price')) || 0;
        var currlabel= $(this).attr('data-label') || '';
        var currinput= userinput;               

        if (currlabel != '' && currinput !='') {  

            if($.isNumeric(pricecost) && pricecost !=0) {
                var updpricecost=pricecost * usernumber;                    
                selectedformvalues.push(currlabel + ": " + settings.currency + updpricecost);
            }               
            else{
                selectedformvalues.push(currlabel + ": " + currinput);
            }           
         }


      }
    }  // End of input type text

    if($("input[type=checkbox]") ||  $("input[type=radio]") )
    {
            if($(this).is(':checked')) {
            var checkboxval= $(this).val();
            if($.isNumeric(checkboxval)) {                                  
                var currlabel= $(this).attr('data-label') || '';
                var currprice= checkboxval;             
                if (currlabel != '') { selectedformvalues.push(currlabel + ": " + settings.currency + currprice); }
                }
            }                           
    }  // End of input type checkbox or radio               

    }); 

    $("#simple-price-details").html("");
        if (selectedformvalues != '') {
            $("#simple-price-details").append("<h3>"+ settings.detailslabel +"</h3>");                              
            $.each(selectedformvalues, function(key,value) {
            $("#simple-price-details").append(value + "<br />");                                
            });
        }

    }// End of UpdateDescriptions()



 this.append('<div id="sidebar"><div id="simple-price-total"><h3     style="margin:0;">' + settings.totallabel + ' </h3><label id="simple-price-total-num"> ' + settings.currency + $.number(total,2) + ' </label></div> <div id="simple-price-details"></div></div>'); 

return this;

};  // End of plugin

  }(jQuery));
在php中,使用此函数可以获得值

echo $_POST['hidden_total']

你的密码在哪里。?如果没有代码,我们就无能为力了。如果没有看到任何代码,我们的猜测可能是:var NumberAsInteger=Match.parseInt(“100欧元”,10);我认为,考虑到这家伙是新来的,2次否决票有点苛刻,没错,他确实需要一个代码示例,但也需要一些友好的指导。你的代码是针对哪个国家的?增值税是什么意思?谢谢你这么多的工作,我读了函数爆炸,但我不明白它是如何工作的谢谢!!!如果我想用这个值来计算增值税,我应该这样做吗?函数calcolaIva($extractedValue[1],$iva){返回$extractedValue[1]+($prezzo*$iva)/100);}echo calcolaIva($extractedValue[1],21);
echo $_POST['hidden_total']