fuller20 Posted March 3, 2010 Report Share Posted March 3, 2010 Ok, I'm very new to adding javascript to caspio data forms. I've tried to insert the javascript outlined in the topic found here: viewtopic.php?f=13&t=12180&p=13937&hilit=sum+column#p13937 But when I try to run it, it does nothing. I've changed the columns to the correct columns in my table. If I uncheck the "disable script debugging" in the options on my browser, I get the error, Line 39: Error: '10.innerHTML' is null or not an object Column 10 is the column I'm trying to sum and it is not null. I've tried to change it to different columns to be sure I have the correct column, but it gives me the same result no matter what. I've tried this on IE7 and IE8. If somone could provide me a solution to this I would greatly appreciate it. Totalling columns is something I will need to do a lot of. Thanks. Quote Link to comment Share on other sites More sharing options...
sbelini Posted March 4, 2010 Report Share Posted March 4, 2010 Hi, have you enabled parameter in the datapage settings? Quote Link to comment Share on other sites More sharing options...
fuller20 Posted March 5, 2010 Author Report Share Posted March 5, 2010 Yes, advanced settings and parameters are enabled. Is there something I'm missing in the parameters that would cause the error I'm getting? I know this has to be something simple, I just can't figure out what it is. Thanks in advance for the help. Quote Link to comment Share on other sites More sharing options...
sbelini Posted March 5, 2010 Report Share Posted March 5, 2010 You mention you are getting an error at line 39. Line 39 in the sample is: v_rev = cells[3].innerHTML; What do you have in your line 39? Quote Link to comment Share on other sites More sharing options...
fuller20 Posted March 8, 2010 Author Report Share Posted March 8, 2010 I changed the 3 on line 39 to a 10 because that's the row I need to total. So the line says, v_rev = cells[10].innerHTML; Here is the whole jscript segment. I'm still at a loss on this so if someone can help me figure out what is wrong I would appreciate it. Thanks. function NumberFormatted(amount,decimal) { if(isNaN(amount)) i = 0.00; else { var v_number = parseFloat(amount); var v_minus = ''; if(v_number < 0) v_minus = '-'; v_number = Math.abs(v_number); v_number = Math.round(v_number*Math.pow(10,decimal)); v_number = v_number/Math.pow(10,decimal); v_numStr = new String(v_number); v_decStr = new String(Math.pow(10,decimal)); if(v_numStr.indexOf(".") < 0) v_numStr = v_numStr + "." + v_decStr.substr(1,v_decStr.length); else v_numStr = v_numStr + v_decStr.substr(1,v_decStr.length); return (v_minus + v_numStr.substr(0,v_numStr.indexOf(".") + decimal + 1)); } } function f_calTotal() { var v_totalRev = 0; var v_rev = 0; var cas_form = document.getElementById("cb_resultTotal"); if (cas_form.getElementsByTagName("table").length > 0) { var cas_rows = cas_form.getElementsByTagName("table")[1].getElementsByTagName("tr"); for(var rowIndex=1; rowIndex < cas_rows.length; rowIndex++) { var cells = cas_rows[rowIndex].getElementsByTagName("td"); /* 1 – change value inside brackets to choose column to calculate sum */ v_rev = cells[10].innerHTML; if ( v_rev != " " && !isNaN(v_rev.substr(1))) v_totalRev = v_totalRev + parseFloat(v_rev); } var v_nrow = cas_rows.length; cas_form.getElementsByTagName("table")[1].insertRow(v_nrow); var o_lastRow = cas_form.getElementsByTagName("table")[1].rows[v_nrow]; o_lastRow.style.background = "#385C7E"; o_lastRow.insertCell(0); o_lastRow.insertCell(1); o_lastRow.insertCell(2); o_lastRow.insertCell(3); o_lastRow.insertCell(4); o_lastRow.insertCell(5); o_lastRow.insertCell(6); o_lastRow.insertCell(7); o_lastRow.insertCell(8); /* 2 – Display the “Total†label (2 lines below) */ var v_colText = o_lastRow.insertCell(9); v_colText.innerHTML = " Total"; var v_colValue = o_lastRow.insertCell(10); /* 3 – Display the result of the calculation (2 lines below) */ v_colValue.innerHTML = " $" + NumberFormatted(v_totalRev,2) + ""; o_lastRow.insertCell(11); o_lastRow.insertCell(12); } } f_calTotal(); Quote Link to comment Share on other sites More sharing options...
sbelini Posted March 8, 2010 Report Share Posted March 8, 2010 So you have a tabular result with 11 columns, right? Where can one see this datapage? Quote Link to comment Share on other sites More sharing options...
fuller20 Posted March 8, 2010 Author Report Share Posted March 8, 2010 Actually there are 13 columns. Column #10 is the one I'm trying to total. Unfortunately, I can't post the link to where the datapage is because it cotains data I don't want to broadcast to whoever wants to see it. I can answer any questions though, if someone has some suggestions on why I'm getting this error. Thanks. Quote Link to comment Share on other sites More sharing options...
sbelini Posted March 9, 2010 Report Share Posted March 9, 2010 hi, if you want to calculate the results in column #10, then you shoud refer to it as index 9 (remember, the first column is 0, the second is 1, and so on... then the tenth column is 9) so your code should be: var v_colValue = o_lastRow.insertCell(9); also make sure all other indexes. finally, make sure the field values are of type "number" or "text" (and have numeric values) Quote Link to comment Share on other sites More sharing options...
fuller20 Posted March 10, 2010 Author Report Share Posted March 10, 2010 hello, Thanks for the response. It is the correct column. It is column 10 starting with 0 as the first column. The column is of format number and there are no nulls in the column. What am I missing here? This can't be such a complex problem. There has to be something small that I'm missing if this code is supposed to work at all. Thanks. Quote Link to comment Share on other sites More sharing options...
sbelini Posted March 10, 2010 Report Share Posted March 10, 2010 Can you check and make sure that the option to download the results is "unchecked"? Quote Link to comment Share on other sites More sharing options...
fuller20 Posted March 11, 2010 Author Report Share Posted March 11, 2010 Yes, it is unchecked. There is no details page as well. Not sure if that matters at all. But something has to be the culprit. And I imagine it's something simple since this code is supposed to work in general. Thanks. Quote Link to comment Share on other sites More sharing options...
sbelini Posted March 15, 2010 Report Share Posted March 15, 2010 Hi, Are you having the issue in the webpage where the Datapage was deployed or when you open the Datapage inside Caspio Bridge application? Quote Link to comment Share on other sites More sharing options...
fuller20 Posted March 16, 2010 Author Report Share Posted March 16, 2010 The error I posted was from a delpoyed version in IE. But now that I try it again within Caspio bridge, I realized it's a different error there. The error I get when running in Caspio is: Line: 605 Error: 'getElementsByTagName(...).1' is null or not an object Here is a screenshot of the error and a sample of what the report the javascript is supposed to be summing from looks like. http://ReportError.gif[/img] It's supposed to be summing column 10 (Plan Comm), but as you can see it's not making it past the above error. It's not even getting to the point of adding the label "total". Thanks for the continued help. Quote Link to comment Share on other sites More sharing options...
sbelini Posted March 16, 2010 Report Share Posted March 16, 2010 My advise is: start all over. Copy and paste the JS code as it is in the forums. Then start making small changes to it and immediatelly checking in inside Caspio (not in a deployed web page). Once you get it to work inside Caspio, deploy it and check. My best guess it that you have more than one table in the webpage you have the Datapage deployed. So the table indexes in the code should be updated (lines 34, 46,47) accordingly. Now, since you mention you are getting errors inside Caspio as well, I advise you to start over and take smaller steps to see if you can pinpoint where the error is appearing. Best, sbelini. Quote Link to comment Share on other sites More sharing options...
aam82 Posted November 10, 2015 Report Share Posted November 10, 2015 Hi old thread! I am encountering the same. I tried disabling ajax and downloading and record index and whatnot. I've tried some different selectors, no luck. Quote Link to comment Share on other sites More sharing options...
Xiang Posted November 27, 2015 Report Share Posted November 27, 2015 Hi aam82, How are you doing? What code do you use? I clicked the link, but page was not found. If you post the code, maybe I can help. Have a nice weekend! Quote Link to comment Share on other sites More sharing options...
Barbarasko Posted November 28, 2015 Report Share Posted November 28, 2015 Hi, have you enabled parameter in the datapage settings? Quote Link to comment Share on other sites More sharing options...
MayMusic Posted December 1, 2015 Report Share Posted December 1, 2015 fuller20 can you please update the link to the post you are referring to? The link throws 404 error message Quote Link to comment Share on other sites More sharing options...
MayMusic Posted December 1, 2015 Report Share Posted December 1, 2015 The provided link is not valid which post you are referring to? Quote Link to comment Share on other sites More sharing options...
aam82 Posted March 31, 2016 Report Share Posted March 31, 2016 This thread is still relevant because we still can't aggregate calculated fields based on subqueries (which was added and then retracted as a feature to Bridge 9). The OP was referring to the Caspio provided JS from the forum http://forums.caspio.com/index.php/topic/3171-js-calculate-column-sum-in-the-result-page/ The script can be fixed to work if you change the table array index from [1] to [2] in the three places where it is used in the script, as in var o_lastRow = cas_form.getElementsByTagName("table")[1].rows[v_nrow]; However, Grouping breaks the script it's not clear how to use this for multiple columns 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.