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...
- The 'cost' field is only disabled after an update to 'design' so the user could type manually
- 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