This topic is locked

code help

5/28/2008 4:53:58 AM
PHPRunner General questions
G
garethp authorDevClub member

Hi
I have the following Javascript adapted from a previous post by Jane. I only have 2 fields - 'design' and 'cost'

<script>

{literal}

var x = document.editform.value_design;

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

var design = document.editform.value_design.value;

var cost = document.editform.value_cost.value;

cost = parseFloat(design) * 2;

document.editform.value_cost.value = cost;

} {/literal} </script>


This works well with the cost field being updated to 2design. However there is one problem - I want the 'cost' field to be read only. If I do this the normal way in the properties the javascript will not work. So I tried the following from a previous post.

<script>

{literal}

var x = document.editform.value_design;

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

var design = document.editform.value_design.value;

var cost = document.editform.value_cost.value;

cost = parseFloat(design)
2;

document.editform.value_cost.value = cost;
} {/literal} </script>


However this caused 2 problems...

  1. The 'cost' field is only disabled after an update to 'design' so the user could type manually
  2. On save the 'cost' value reverts back to the previous value - it is not updated to the new value even thought the field show the new correct value throught the Javascript.
    So I tried the following...
    <script>

    {literal}

    [color=#FF0000]document.forms.editform.value_cost.disabled=true;

    var x = document.editform.value_design;

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

    var design = document.editform.value_design.value;

    var cost = document.editform.value_cost.value;

    cost = parseFloat(design) * 2;

    document.editform.value_cost.value = cost;
    } {/literal} </script>


This sorted out (1) above but the problem (2) still exists - the 'cost' field always reverts back to the old value.
Can anyone help as this is driving me mad - my first experience of Javascript and so close!!!
Thanks Gareth

J
Jane 5/28/2008

Hi,
try to save cost value directly in the Before record added/updated event:

$values["cost"] = $_POST["value_cost"];

G
garethp authorDevClub member 5/28/2008

Jane
Thanks for superquick reply.
I have tried this and it now saves as 0 (zero).
Any other ideas - really appreciate your help. For info I put my code in jsut before </body></html> in html mode in the visual editor - is this correct?

G
garethp authorDevClub member 5/30/2008

hi

can anyone help with this problem - I so need this to work
thanks in advance
gareth

J
Jane 5/30/2008

Gareth,
Please publish your project on Demo Account and send to support@xlinesoft.com a URL to your pages along with instructions on reproducing this error.

I'll find what's wrong with your project inspecting it at Demo account site.

G
garethp authorDevClub member 5/30/2008

Jane
Thanks - uploaded and sent to suuport
Gareth