Elena Posted November 9, 2015 Report Share Posted November 9, 2015 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; Quote Link to comment Share on other sites More sharing options...
Jan Posted November 9, 2015 Report Share Posted November 9, 2015 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; Quote Link to comment Share on other sites More sharing options...
Elena Posted November 9, 2015 Author Report Share Posted November 9, 2015 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> Quote Link to comment Share on other sites More sharing options...
Jan Posted November 16, 2015 Report Share Posted November 16, 2015 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.