Niranjan Posted May 26, 2015 Report Share Posted May 26, 2015 I need to ensure that values in a column in a tabular report are between 0 and 100 (They are meant to be a percentage impact figure to be entered by the user). I studied the JS example of creating column totals in a tabular report (see http://forums.caspio.com/index.php/topic/3171-js-calculate-column-sum-in-the-result-page/ ) and modified the code as follows, but I cannot get the script to fire at all. I added a number of debugging statements to no avail. I have tried an "onsubmit" type of call as well, apart from the below example. Ideally there should be a way to fire this at the end of adding / editing each row, but I could live with at the end of the whole page as well. At the end of the Header: <div id="cb_checkImpact"> At the beginning of the Footer: </div> <script> function f_check() { alert('Inside function'); var v_impact = 0; var cas_form = document.getElementById("cb_checkImpact"); if (cas_form.getElementsByTagName("table").length > 0) { alert('Found records'); var cas_rows = cas_form.getElementsByTagName("table")[1].getElementsByTagName("tr"); for(var rowIndex=1; rowIndex < cas_rows.length; rowIndex++) { alert('Inside row loop'); var cells = cas_rows[rowIndex].getElementsByTagName("td"); /* 1 – change value inside brackets to choose column to perform validation */ v_impact = cells[2].innerHTML; alert('Found value:'); alert(v_impact); if ( parseFloat(v_impact) < 0 || parseFloat(v_impact) > 100){ alert('Value in %Impact field must be between 0 and 100'); return(false); } alert('No issues found'); } } alert('About to call function'); f_check(); alert('Finished function'); </script> Quote Link to comment Share on other sites More sharing options...
Jan Posted May 26, 2015 Report Share Posted May 26, 2015 Hello Niranjan, Is the "100" allowed? If not, you can go to the "Editing" tab and in the "Character length: Max:" field enter "2". Then user can enter only numbers from 0 to 99. Does it work for you? Quote Link to comment Share on other sites More sharing options...
Niranjan Posted May 28, 2015 Author Report Share Posted May 28, 2015 Ok - not ideal because I may need to allow 100 as a valid number, but must say creative thinking and good plan B if nothing else works thanks :-) how about preventing negative values? Quote Link to comment Share on other sites More sharing options...
aam82 Posted March 31, 2016 Report Share Posted March 31, 2016 Niranjan, see my post here http://forums.caspio.com/index.php/topic/3183-cant-get-jscript-column-total-to-work/#entry17705 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.