Parma2015 Posted December 4, 2015 Report Share Posted December 4, 2015 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 Quote Link to comment Share on other sites More sharing options...
Walter Posted December 4, 2015 Report Share Posted December 4, 2015 Hi Jan, What is the DataType of the field that marked with the error? What is icon of this field in the DataPage? And which decimal symbol do you use? And which is allowed for number input? Quote Link to comment Share on other sites More sharing options...
Parma2015 Posted December 7, 2015 Author Report Share Posted December 7, 2015 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 Quote Link to comment Share on other sites More sharing options...
Walter Posted December 7, 2015 Report Share Posted December 7, 2015 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. Quote Link to comment Share on other sites More sharing options...
Parma2015 Posted December 8, 2015 Author Report Share Posted December 8, 2015 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 Quote Link to comment Share on other sites More sharing options...
Kurumi Posted October 29, 2018 Report Share Posted October 29, 2018 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! 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.