Jump to content

Calculation In Submission Form


Recommended Posts

Hi!

I have created a calculation in a submission form that calculate hours from a start hour and start minute to a stop hour and stop minute. I also subtract for a lunch break in minutes. I also store these values in my table, formatted as integer

The calculation goes as it should, and the value is stored in a field ("Hours").

However, I got problems when submitting and when the number of hours is not a whole number. Then I get the message "Must be a number". The table fiels is formatted as number, and should accept decimals. I also tried differend ways of formatting the result as number with two decimals, but I still get the same massage.

Here is the code:

 

<SCRIPT LANGUAGE="JavaScript">
function calcHours()
{

var startH = document.getElementById("InsertRecordStartHr").value;
var startM = document.getElementById("InsertRecordStartMin").value;
var lunchM = document.getElementById("InsertRecordLunch").value;
var stopH = document.getElementById("InsertRecordStopHr").value;
var stopM = document.getElementById("InsertRecordStopMin").value;
var hrs = (stopH-startH)- (lunchM/60) + (stopM-startM)/60;
document.getElementById("InsertRecordHours").value= hrs;
}  
document.getElementById("caspioform").onchange=calcHours;
</SCRIPT>
 

I am not sure where the problem occurs. Is there anybody that can see what could be the problem here?

 

I have also concidered to display the calculated value in a virtual field (if that is possible), so the value is not stored in my table. Then I could do the calculation again in a view when reporting hours. At least I will avoid to break the normalization rules that way :-/

Regards

Jan

Link to post
Share on other sites

Hi!

Thanks for your reply.

The data type in the table is number, which means it couldt be a number with decimals.

The field in my submission form is a text field, and here ared cilcel with an "X" inside icon appear when I try to submit, followed by the massage "Must be a number".

I use comma as separator in my form but in the table, it is stored with dot as separator. (input is Scandinavian style as I am located in Norway).

As I use text field for input, I havent been able to format the number. I used "Display only", as I then was able to format the number with comma saparator. That didn't work either, as nothing showd up in that field.

Regards

Jan

Link to post
Share on other sites

Hi Jan,

 

Have you alerted every value?

I mean,

<SCRIPT LANGUAGE="JavaScript">
function calcHours()
{
var startH = document.getElementById("InsertRecordStartHr").value;
alert(startH);
var startM = document.getElementById("InsertRecordStartMin").value;
alert(startM);
var lunchM = document.getElementById("InsertRecordLunch").value;
alert(lunchM);
var stopH = document.getElementById("InsertRecordStopHr").value;
alert(stopH);
var stopM = document.getElementById("InsertRecordStopMin").value;
alert(stopM);
var hrs = (stopH-startH)- (lunchM/60) + (stopM-startM)/60;
alert(hrs);
document.getElementById("InsertRecordHours").value= hrs;
}  
document.getElementById("caspioform").onchange=calcHours;
</SCRIPT>

It seems, you get "NA" on one of steps.

Link to post
Share on other sites

Hi!

I get values for all variables, and none shows NA or NAN.

However, it seems like I need to replace the dot (.) with a comma (,) to make it work. Perhaps this is due to the localization which is formatted that way.

In the table, all numbers are formattet with dots, but in my forms I need comma.

Could there be a way to format number this way through Java?

Maybe I have to convert it to a string first, then replace the dot, and then back to numberformat?

Regards

Jan H

Link to post
Share on other sites
  • 2 years later...

Hi @Parma2015,

As of July 12, 2018, Caspio introduced new features which you can find here: https://howto.caspio.com/release-notes/caspio-bridge-13-0/

This release includes a new feature, Calculated Values in Submission Forms.  This allows you to generate calculations which you can use for your Hours field.

Check these videos for more information:

 

I hope this helps!

Link to post
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
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...