Jump to content

Calculating Values In Details Page


Recommended Posts

Hi there,

 

I got the below code from the Javascript section of this community forum.

It doesn't seem to be working for me and my details page of my report.

 

I also wanted to add the percentage symbol after each field.

 

I would appreciate it so much if you can take a look and let me know where I'm going wrong.

 

Thank you so much in advance.

 

 

 

function calculate()
 {
   var task1 = parseFloat(document.getElementById(“EditRecordDuties_Task1_Time").value) +'%';
   var task2 = parseFloat(document.getElementById(“EditRecordDuties_Task2_Time").value) +'%';
   var total  = (task1 + task2);
   document.getElementById(“EditRecordTotalTaskTime").value = Math.round(total) + '%';
}

document.getElementById("caspioform").onsubmit=calculate;
 

Link to comment
Share on other sites

Hi Elena,

 

Please try the following code:

function calculate()
 {
   var task1 = parseFloat(document.getElementById(“EditRecordDuties_Task1_Time").value);
   var task2 = parseFloat(document.getElementById(“EditRecordDuties_Task2_Time").value);
   var total  = task1 + task2;
   total = Math.round(total);
   var result = total + "%";
   document.getElementById(“EditRecordTotalTaskTime").value = result;
 }

document.getElementById("caspioform").onsubmit=calculate;
Link to comment
Share on other sites

Hi Jan,

 

Many thanks for the guidance. It is still not working for me. I have below the script that I have on my footer. 

I do have two functions that I am trying to execute (the last of which is the calculate function). I am wondering if having multiple functions this way is not kosher. I tried writing the two closing syntax on top of another, that didn't work either, as in: 

 

}

}

document.getElementById("caspioform").onsubmit = trim_func;

document.getElementById("caspioform").onsubmit=calculate;

 

So, now, below is what I have - which doesn't work as well.

 

I wonder also, should I replace the "Id" with "name". Because those Id are actually my field names? 

 

Elena 

 

 

 

<script>

function trim_func()
{
  var fieldname = "Job_Purpose";
  var fieldname1 = "Duties_Task1";
  var fieldname2 = "Duties_Task2";
 
fieldname = "EditRecord" + fieldname + fieldname1 + fieldname2;
  var entered_text = document.getElementById(fieldname).value;
  var entered_text = document.getElementById(fieldname1).value;
  var entered_text = document.getElementById(fieldname2).value;
 
var n = 1;
  for (i=0;1<100;i++)
  {
    n = entered_text.indexOf("\n\n");
    if(n>-1)
      entered_text = entered_text.replace("\n\n","\n");
    else break;
  }
document.getElementById(fieldname).value = entered_text;
document.getElementById(fieldname1).value = entered_text;
document.getElementById(fieldname2).value = entered_text;
}
document.getElementById("caspioform").onsubmit = trim_func;
 
 
function calculate()
 {
   var task1 = parseFloat(document.getElementById(“EditRecordDuties_Task1_Time").value);
   var task2 = parseFloat(document.getElementById(“EditRecordDuties_Task2_Time").value);
   var total  = task1 + task2;
   total = Math.round(total);
   var result = total + "%";
   document.getElementById(“EditRecordTotalTaskTime").value = result;
 }
document.getElementById("caspioform").onsubmit=calculate;
 
</script>
Link to comment
Share on other sites

Hi Elena,

 

As far as I know, if "onsubmit" is used more than one time, only the first "onsubmit" works.

You can rewrite the whole code as well:

<script>
function trim_func()
{
   var task1 = parseFloat(document.getElementById("EditRecordDuties_Task1_Time").value);
   var task2 = parseFloat(document.getElementById("EditRecordDuties_Task2_Time").value);
   var total  = task1 + task2;
   total = Math.round(total);
   var result = total + "%";
   document.getElementById("EditRecordTotalTaskTime").value = result;

  var fieldname = "Job_Purpose";
  var fieldname1 = "Duties_Task1";
  var fieldname2 = "Duties_Task2";

  fieldname = "EditRecord" + fieldname + fieldname1 + fieldname2;
  var entered_text = document.getElementById(fieldname).value;
  var entered_text = document.getElementById(fieldname1).value;
  var entered_text = document.getElementById(fieldname2).value;

  var n = 1;
  for (i=0;1<100;i++)
  {
    n = entered_text.indexOf("\n\n");
    if(n>-1)
      entered_text = entered_text.replace("\n\n","\n");
    else break;
  }
  document.getElementById(fieldname).value = entered_text;
  document.getElementById(fieldname1).value = entered_text;
  document.getElementById(fieldname2).value = entered_text;
}
document.getElementById("caspioform").onsubmit=trim_func;

</script>

I hope, it works.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...