This topic is locked

add/edit pages

5/22/2008 10:46:19 AM
PHPRunner General questions
G
garethp authorDevClub member

Hi
I have a caculated field that is 5 fields added together as follows in the edit sql query

design+tooling+project+production+installation AS cost


Is there any way I can see this in add and edit screen so that is updates as I change the fields before I click save?
I would like to be able to see this formula changing as I edit each of the 5 fields. At the moment I can not see when I add the record what the total is.
Thanks
Gareth

S
swanside 5/22/2008

Hi

I have a caculated field that is 5 fields added together as follows in the edit sql query
Is there any way I can see this in add and edit screen so that is updates as I change the fields before I click save?
I would like to be able to see this formula changing as I edit each of the 5 fields. At the moment I can not see when I add the record what the total is.
Thanks
Gareth


I dont think so, as the page needs to refresh to show the details.
It would be nice if it did show the changes,

J
Jane 5/23/2008
G
garethp authorDevClub member 5/23/2008

Jane
I am liking this a lot.
I have managed to add 2 fields together with the followin code...

<script>

{literal}

var x = document.editform.value_design;

var y = document.editform.value_project;

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

var design = document.editform.value_design.value;

var tooling = document.editform.value_tooling.value;

var project = document.editform.value_project.value;

document.editform.value_tooling.value = parseFloat(design) +parseFloat(project);
} {/literal} </script>


Don't know what it means but it sure works well!!!
I have 2 questions if that OK...

  1. If one of the fieds is blank/null the calculated fied show NaN - is there a way that a blank field is treated a zero. For example 1 + null = 1
  2. I have added this coded to the bottom of the code in visual editor - is there anyway to do this using an event so it is not lost on rebuild?
    Many thanks - this will make such a difference to me.
    Gareth

J
Jane 5/26/2008

Gareth,
you can check values before calculation using isNaN() function:

var design = document.editform.value_design.value;

if (isNaN(design))

design = 0;



More info here:

http://www.w3schools.com/jsref/jsref_isNaN.asp
Code added on the Visual Editor is saved on rebuild.

G
garethp authorDevClub member 5/26/2008

Jane
Thanks for the response - I am confused where I should be adding the code in visual editor as it is currently disappearing on rebuild. Can I explain where I have added it...

  1. I select the edit page in the visual editor
  2. I switch to html mode
  3. I go to the bottom and add my code between </script> and </BODY></HTML>.
    THis works fine but disappears on rebuild.
    I had initially tried to do it by clicking "insert php code snippet" but could never get this to work - and besides this {doevent name="capex_Event3"} also dissappears from the edit page on rebuild although the code seems to stay in an event.
    What am I doing wrong? Thanks for your help