This topic is locked

Calculate fields Via Visual Editor

1/22/2008 8:15:20 AM
PHPRunner General questions
L
Lisa2006 author

Hi Support,
I have placed the code snippet in Visual Editor on the invoices_add.php
<script>

{literal}

var x = document.editform.value_net;

x.onchange = x.onkeyup = function() {

var net = document.editform.value_net.value;

var vat = document.editform.value_vat.value;

var gross = document.editform.value_gross.value;

document.editform.value_vat.value = net * 0.175;

document.editform.value_gross.value = net + vat;

document.forms.editform.value_gross.disabled=true;

document.forms.editform.value_vat.disabled=true;

} {/literal} </script>
When executed i get the following page:


When i enter a value for document.editform.value_vat.value = net * 0.175;)
However, the gross is does not calculate correctly.
gross = net + vat
Please Help
Lisa

[/color]

J
Jane 1/22/2008

Lisa,
try to use this code:

<script>

{literal}

var x = document.editform.value_net;

x.onchange = x.onkeyup = function() {

var net = document.editform.value_net.value;

var vat = document.editform.value_vat.value;

var gross = document.editform.value_gross.value;

document.editform.value_vat.value = net 0.175;

document.editform.value_gross.value = net + net
0.175;

document.forms.editform.value_gross.disabled=true;

document.forms.editform.value_vat.disabled=true;

} {/literal} </script>

L
Lisa2006 author 1/22/2008

Hi Jane,
I've applied the amended code snippet, but still get bad results


Please HELP!!!

J
Jane 1/22/2008

Lisa,
sorry for my fault.

Here is the correct code:

<script>

{literal}

var x = document.editform.value_net;

x.onchange = x.onkeyup = function() {

var net = document.editform.value_net.value;

var vat = document.editform.value_vat.value;

var gross = document.editform.value_gross.value;

document.editform.value_vat.value = parseFloat(net) 0.175;

document.editform.value_gross.value = parseFloat(net) + parseFloat(net)
0.175;

document.forms.editform.value_gross.disabled=true;

document.forms.editform.value_vat.disabled=true;

} {/literal} </script>

L
Lisa2006 author 1/22/2008

Hi Jane,
Your a Star!!!



Works 100%
to 2 decimal places.
Thank you so much
Lisa

S
swanside 1/22/2008

Hi Jane,

Your a Star!!!



Works 100%
to 2 decimal places.
Thank you so much
Lisa


In the Visual editor, double click on the item and in the popup window select to view as currency.

J
Jane 1/23/2008

Lisa,
use this code:

<script>

{literal}

var x = document.editform.value_net;

x.onchange = x.onkeyup = function() {

var net = document.editform.value_net.value;

var vat = document.editform.value_vat.value;

var gross = document.editform.value_gross.value;

vat = parseFloat(net) 0.175;

gross = parseFloat(net) + parseFloat(net)
0.175;

vat = vat.toFixed(2);

gross = gross.toFixed(2);

document.editform.value_vat.value = vat;

document.editform.value_gross.value = gross;

document.forms.editform.value_gross.disabled=true;

document.forms.editform.value_vat.disabled=true;

} {/literal} </script>