Jump to content

Recommended Posts

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>
 
Link to post
Share on other sites
  • 10 months later...

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...
×
×
  • Create New...