Calculation of Fields

Hi ... I am very much a beginner so please have patience.
I am wanting to calculate the difference between Start kilometres and End kilometres.I have tried:
$("#field1,#field2").on("change", function(){
	$("#total").val(parseInt($("#field1").val()) + parseInt($("#field2").val()));
});
from the FAQ's but I am not getting a result.
Any help?
Gr GreyHead 19 Nov, 2018
Hi Karl,
​
What are the IDs of your inputs - you need to replace total, field1 and field2 with these.
​
And do you have this code in a JavaScript Custom element?
​
Bob
Hi Bob
​
Thanks for the response.
The actual that I have used is as follows and it is in a Java custom element
​
$("#field_text19,field_text20").on("change", function(){
$("#field_text23").val(parseInt($("field_text19").val()) + parseInt($("#field20").val()));
});
Gr GreyHead 19 Nov, 2018
Hi Karl,
​
Please post a link to the form so we can take a quick look.
​
Bob
This is link to the front end ... do you need access to Joomla Admin?
​
www.dataware.co.za
Gr GreyHead 19 Nov, 2018
Hi Karl,
​
Your JavaScript needs to use the IDs of the form elements which are start_kms, end_kms and trip_kms
​
Also I suspect that you should not be adding the start and end kms to get the trip length.
​
Bob
Haha ... you are right ... my calculation is incorrect. I just used the simplest calc until I get it working, and understand what I am doing.
Then I will worry about the maths 🙂
​
I have made the change to no avail:
​
$("#start_kms,end_kms").on("change", function(){
$("trip_kms").val(parseInt($("start_kms").val()) + parseInt($("end_kms").val()));
});
​
I have my start, end and trip one beneath the other with the Java beneath all 3.
I have all 4 in a Group Area.
Gr GreyHead 19 Nov, 2018
Hi Karl,
​
Now you have left out most of the # s which are used to identify the strings as IDs
$("#start_kms, #end_kms").on("change", function(){
$("#trip_kms").val(parseInt($("#end_kms").val()) - parseInt($("#start_kms").val()));
});
Important - don't copy and paste the code from the forums as that adds invisible characters that may stop the code working :-(
​
Bob
Gr GreyHead 19 Nov, 2018
Hi Karl.
​
There is a JavaScript Error on the page - it looks like some of those pesky invisible characters have gotten into the script.
​
Bob
Thanks so much for the help ... it's working 🙂
​
After reading:
​
Important - don't copy and paste the code from the forums as that adds invisible characters that may stop the code working :-(
​
I realized that I had copied the script originally from the FAQ's.
I manually typed it out and it works.
​
Again thank you.
One more question:
​
I have a date field and a time field. Is there any way I have these defaulting to current date and time when I open the form?
he healyhatman 19 Nov, 2018
In the "value" field put {date:format} change foprmat depending on the field.
he healyhatman 20 Nov, 2018
No it should match the format of the field's "actual value" so probably {date:Y-m-d}
Thanks so much ... that works🙂
​
Would the current time be similar {time:HH:mm} ?
he healyhatman 20 Nov, 2018
What do you mean? Have you set it to time instead of date or datetime?
I have the following:
​
Value: {date:H:i}
Start day: Monday
Start mode: Day
Type: Date
Display: HH:ss
he healyhatman 20 Nov, 2018
Value: {date:H:i}
Type: Time
Display format: HH:mm
Real Format: HH:mm
​
DO NOT copy+paste from the forums, adds hidden characters
Great thanks. I am getting a default time but it is GMT. My PC and Joomla time are set at GMT+2
he healyhatman 20 Nov, 2018
{date/timezone:format$options}
​
http://php.net/manual/en/timezones.php
Have I understood the options correctly?
I still get GMT
​
{date/timezone:H:i$Africa/Johannesburg}
he healyhatman 20 Nov, 2018
No, the timezone goes where I put the word "timezone"
Thanks so much for your support and patience ... much appreciated.
​
All working correctly 🙂
Hi ...
​
The date field is formatted as I wanted on the screen.
When I Submit the email that I have receive has a different format for the date.
Can I 'force' the format to be the same on screen and in the email received?
Thanks
he healyhatman 20 Nov, 2018
{date:format$(data:date_field)}
​
Or just change the "actual value" to the format you want
This topic is locked and no more replies can be posted.