Jump to content

JAVASCRIPT TO PHP


RCS

Recommended Posts

I'M TRYING TO CHANGE THE FOLLOWING JAVASCRIPT TO PHP, CAN SOMEONE PLEASE GIVE ME A RUN DOWN OF HOW TO GO ABOUT THIS??? THANKS IN ADVANCE

 

function calculate(num) {

var tax_on = 0;

var tax_to = 0;

 

num = num.replace(/[^0-9\.]/g,'');

if ( num <= 55000 ) {

tax_on = (num*0.005);

tax_to = (num*0.005);

}

if ( num > 55000 && num <= 250000 ) {

tax_on = (num*0.01)-275;

tax_to = (num*0.01)-275;

}

if ( num > 250000 && num <= 400000 ) {

tax_on = (num*0.015)-1525;

tax_to = (num*0.01)-275;

}

if ( num > 400000 ) {

    tax_on = (num*0.02)-3525;

tax_to = (num*0.02)-4275;

}

    var Sum = tax_on + tax_to;

 

 

document.forms.the_form.tax_on.value = format(tax_on,2);

document.forms.the_form.tax_to.value = format(tax_to,2);

document.forms.the_form.sum.value = format(Sum,2);

 

}

function calculate_com(num) {

var tax_on2 = 0;

var tax_to2 = 0;

 

num = num.replace(/[^0-9\.]/g,'');

if ( num <= 55000 ) {

tax_on2 = (num*0.005);

tax_to2 = (num*0.005);

}

else if ( num > 55000 && num <= 250000 ) {

tax_on2 = (num*0.01)-275;

tax_to2 = (num*0.01)-275;

}

else if ( num > 250000 && num <= 400000 ) {

tax_on2 = (num*0.015)-1525;

tax_to2 = (num*0.01)-275;

}

else if ( num > 400000 && num <= 40000000 ) {

tax_on2 = (num*0.015)-1525;

tax_to2 = (num*0.015)-2275;

}

else {

    tax_on2 = (num*0.015)-1525;

tax_to2 = (num*0.01)+197725;

}

    var Sum2 = tax_on2 + tax_to2;

 

 

document.forms.the_form2.tax_on2.value = format(tax_on2,2);

document.forms.the_form2.tax_to2.value = format(tax_to2,2);

document.forms.the_form2.Sum2.value = format(Sum2,2);

 

}

function format(no, dp)

{

    dp = Math.pow(10, dp);

    var no = (Math.round(no * dp) / dp) + "";

    var first = no.split(".");

    var tmp = new Array;

    var counter = 0;

    var start = first[0].length % 3;

    if (start) tmp[counter++] = first[0].substr(0, start);

    for (var i = start ; i < first[0].length ; i += 3)

        tmp[counter++] = first[0].substr(i, 3);

    first[0] = tmp.join(',');

    return "$"+first.join('.');

}

Link to comment
https://forums.phpfreaks.com/topic/96997-javascript-to-php/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.