Jump to content
  • 0

Auto calculating and submitting a form


GingerDan

Question

So I'm trying to get the value that is already in the current points field, do a calculation as depicted in the switch statement and then fill the field in again with the new number before submitting instantly.   This is all supposed to be done as a way of replacing an SQL update statement. For some reason my EditRecord or document.getElementById doesn't seem to be working at all.

 

<script LANGUAGE="Javascript">
function calculate(){
  var pos = [@pos];
  var points = [@field:CurrentPoints#];
   switch(pos)
   {
       case 1: points += 10; break;
       case 2: points += 8; break;
       case 3: points += 6; break;
       case 4: points += 4; break;
       case -2: points += -2; break;
       default: points += 2; 
   }
  document.getElementById("EditRecordCurrentPoints").innerHTML = points;
}
   document.getElementById("mypage").onsubmit=calculate();

</script>

 

There is already a <div id="mypage"> in the header and a </div> in the footer.

Am I just being very stupid?

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0
On 10/8/2017 at 5:28 AM, GingerDan said:

So I'm trying to get the value that is already in the current points field, do a calculation as depicted in the switch statement and then fill the field in again with the new number before submitting instantly.   This is all supposed to be done as a way of replacing an SQL update statement. For some reason my EditRecord or document.getElementById doesn't seem to be working at all.

 

<script LANGUAGE="Javascript">
function calculate(){
  var pos = [@pos];
  var points = [@field:CurrentPoints#];
   switch(pos)
   {
       case 1: points += 10; break;
       case 2: points += 8; break;
       case 3: points += 6; break;
       case 4: points += 4; break;
       case -2: points += -2; break;
       default: points += 2; 
   }
  document.getElementById("EditRecordCurrentPoints").innerHTML = points;
}
   document.getElementById("mypage").onsubmit=calculate();

</script>

 

There is already a <div id="mypage"> in the header and a </div> in the footer.

Am I just being very stupid?

I suppose that you use update form. You  should use a little bit different syntax, have a look at this post

Link to comment
Share on other sites

  • 0

Hello @GingerDan,

 

I know it's a bit late, but for future references, you can use Calculated Value in Form Element if you want to have calculations in Submission form or Details Page. 

The Calculated Value generates dynamic calculations that automatically update as users interact with your form. 

You may check this link for more details:

https://howto.caspio.com/datapages/datapage-components/calculated-values/

 

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
Answer this question...

×   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...