Calculation of Fields 19 Nov, 2018
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?
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 19 Nov, 2018
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()));
GreyHead 19 Nov, 2018
Hi Karl,

Please post a link to the form so we can take a quick look.

Bob 19 Nov, 2018
This is link to the front end ... do you need access to Joomla Admin?
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 19 Nov, 2018
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.
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 :-(

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 19 Nov, 2018
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. 19 Nov, 2018
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?
healyhatman 19 Nov, 2018
In the "value" field put {date:format} change foprmat depending on the field. 20 Nov, 2018
Thanks ... am I understanding correctly?

healyhatman 20 Nov, 2018
No it should match the format of the field's "actual value" so probably {date:Y-m-d} 20 Nov, 2018
Thanks so much ... that works🙂

Would the current time be similar {time:HH:mm} ?
healyhatman 20 Nov, 2018
What do you mean? Have you set it to time instead of date or datetime? 20 Nov, 2018
I have the following:

Value: {date:H:i}
Start day: Monday
Start mode: Day
Type: Date
Display: HH:ss
healyhatman 20 Nov, 2018
Okay so you see where it says type:date ?
healyhatman 20 Nov, 2018
NO result? Shows nothing at all?
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 20 Nov, 2018
I haven't copied / pasted anything. I type from scratch. 20 Nov, 2018
Great thanks. I am getting a default time but it is GMT. My PC and Joomla time are set at GMT+2
healyhatman 20 Nov, 2018
{date/timezone:format$options} 20 Nov, 2018
Have I understood the options correctly?
I still get GMT

healyhatman 20 Nov, 2018
No, the timezone goes where I put the word "timezone" 20 Nov, 2018
Thanks so much for your support and patience ... much appreciated.

All working correctly 🙂 20 Nov, 2018
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?
healyhatman 20 Nov, 2018

Or just change the "actual value" to the format you want
This topic is locked and no more replies can be posted.