Need to display conditional date in summary

  • snappysites
  • Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 13
  • Thank you received: 0

snappysites created the topic: Need to display conditional date in summary

Hi

I have a form in which a visitor selects a date. I need to display another date in a summary section which is 14 months later than the date selected.

I know how to use conditional fields, but I'm not sure how to express that calculation.
Could someone possibly give me a script for that, please?
#234872
  • Posts: 2483
  • Karma: 86
  • Thank you received: 335

mihaela replied the topic: Need to display conditional date in summary

Hello,

It is possible to do what you want.

The best way to do so is to create a "Hidden input" field where you can display the calculated amount and then based on that new field create a summary field.

In which format is the calendar field?
Depending on that the script will be written.

Regards,

Mihaela
#234888
  • snappysites
  • Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 13
  • Thank you received: 0

snappysites replied the topic: Need to display conditional date in summary

Hi, Mihaela

%d %B, %Y

Thanks
#234889
  • snappysites
  • Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 13
  • Thank you received: 0

snappysites replied the topic: Need to display conditional date in summary

mihaela wrote: Hello,
In which format is the calendar field?


%d %B, %Y
#235830
  • Posts: 2483
  • Karma: 86
  • Thank you received: 335

mihaela replied the topic: Need to display conditional date in summary

Hello,

I will explain how to write a code that will work for date format %d-%m-%Y.

Create an additional Textfield element in your form and give it name "newdate".

Then go to form's Advanced properties > More options > Scripts and in the Initialization script section set Type to Custom.

In the code area below put the following code:
function ff_QuickForm1222998494_init()
{ setInterval( calc, 500);
} // ff_QuickForm1222998494_init

function calc() {
var calend = ff_getElementByName('cal').value.split("-");

var d = new Date(calend[2], calend[1]-1, calend[0]); // January 1, 2000
d.setMonth(d.getMonth() + 14);
var mj = Number(d.getMonth()) + 1; 
ff_getElementByName('newdate').value =d.getDate() + "-"+ mj + "-"+ d.getFullYear() ;

}
NOTE: In order for this to work, you have to replace cal with the calendar element in your form which collects the date in format %d-%m-%Y.

That will do the trick, a date with 14 months added will be displayed in the "newdate" field.

Writing a JavaScript code for non-numeric month representation is a bit more demanding so if you wish to have the non-numeric representation you will need to do some additional coding which is not in the scope of support.

Let me know whether this works as you wanted.

Regards,

Mihaela
#235855
Moderators: ForumSupporttomeperica
Time to create page: 0.119 seconds

New Icon Packs Category!

Crosstec is now offering icon packs.

If you are a paying subscriber, icon packs are automatically added to your account.

Check out our icon packs page!

Live Support Chat Opened!

Join our Discord chat here to receive live support and talk directly to the team!

Summer Sale!

50% discount on all of our extension subscription plans, templates and icon packs!

Get Your Subscription Here

News and Updates

Get informed about new downloads, updates and more in our News and Updates newsletter.

All Extensions Subscription

Get 1 year access to all of our current and future products and 1 year of professional support -- 99 for just 49! (Summer Sale)

No support per domain or website installation limits! Includes all of our current and future Joomla!® extensions, Joomla!® templates for the duration of your membership. This means, by purchasing an All Extensions Subscription you'll have it all covered!

Get it from here

3rd Party Discount - 25% Off

We help you to keep your costs under control. If you are a new member and purchased a form building tool from a different form vendor, then you'll get a 25% discount on our subscription plans.

How to receive the discount:

Send us a quick email to sales@crosstec.org with a proof of purchase (for example a paypal receipt), await payment instructions and enjoy your membership!

Live Support Chat Opened!

Join our Discord chat here to receive live support and talk directly to the team!

Community Reward

Help us to create new extensions and plugins! With only $5 you help us a lot and get unlimited download access to all of our products, professional support and even more. Get your reward now!

Read More Here