TOPIC:

Add Months to Date 9 months 3 days ago #241085

  • TheMuffinMan's Avatar
  • TheMuffinMan
  • Offline
  • Developer
  • Developer
  • Posts: 10064
  • Karma: 167
  • Thanks: 807
I am sure the reason is because a js error has been thrown.
The reason is likely this part
m = pd.getMonth();

"pd" is the plain string from that field, not a date object. We first have to convert it like this:
pd = new Date( ff_getElementByName('purchdate').value );

Then you want to add additional warranty length in months. We might need to convert the string value to an integer, just to make sure it ends up in a valid calculation (note that getMonth()/setMonth() starts with 0 in js).
wl = parseInt( ff_getElementByName('warrantylength').value );

Last but not least, we want to store the date back, but as string into your 'warrantyexpiration' element and not the date object:
ff_getElementByName('warrantyexpiration').value = pd.toString();

Given that your date format isn't compatible with "new Date()", you might need to split your date value and transform it so it will give proper result.

Have a look at the "new Date()" examples here if the above isn't working and showing odd dates:

developer.mozilla.org/en-US/docs/Web/Jav.../Global_Objects/Date

Regards,
Markus

Please Log in or Create an account to join the conversation.

Last edit: Post by TheMuffinMan.

Add Months to Date 9 months 3 days ago #241101

  • Topic Author
  • emtbrian2000
  • Offline
  • Fresh Breezer
  • Fresh Breezer
  • Posts: 18
  • Thanks: 0
Thanks for getting me on the right track! I was able to use that to find a solution. This was the code I ended up using to get it formatted correctly:
function ff_warrantyexpiration_validation(element, message)
{
	var pd = new Date(ff_getElementByName('purchdate').value);
	wl = parseInt( ff_getElementByName('warrantylength').value );
	m = pd.getMonth();
	pd.setMonth(m + wl + 1);
	var y = pd.getFullYear();
        var m = pd.getMonth();
        var d = pd.getDate();
        expdate = new String(m + "-" + d + "-" + y);

	element.value = expdate.toString();
    
    return '';
}

Please Log in or Create an account to join the conversation.

Add Months to Date 9 months 3 days ago #241121

  • TheMuffinMan's Avatar
  • TheMuffinMan
  • Offline
  • Developer
  • Developer
  • Posts: 10064
  • Karma: 167
  • Thanks: 807
Hi,

so you're happy or do you need further help?

Regards,
Markus

Please Log in or Create an account to join the conversation.

Add Months to Date 9 months 3 days ago #241126

  • Topic Author
  • emtbrian2000
  • Offline
  • Fresh Breezer
  • Fresh Breezer
  • Posts: 18
  • Thanks: 0
I'm happy. Thanks for the help!

Please Log in or Create an account to join the conversation.

Add Months to Date 9 months 3 days ago #241130

  • TheMuffinMan's Avatar
  • TheMuffinMan
  • Offline
  • Developer
  • Developer
  • Posts: 10064
  • Karma: 167
  • Thanks: 807
Great, please make sure to support the project by leaving a small review here:

extensions.joomla.org/extension/contacts...orms/breezing-forms/

Much appreciated!

Regards,
Markus

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
  • 2
Moderators: ForumSupport
Time to create page: 0.049 seconds

BreezingForms Pro 1.4.7 for WordPress Released!

Available in the membership section.

September Discount!

Massive discounts on all subscriptions!

Get Your Subscription Here

Quick Links

Downloads

BreezingForms

ContentBuilder

BreezingCommerce

Templates

Documentation

BreezingForms

ContentBuilder

BreezingCommerce

Apprendre BreezingForms (French Community)

Apprendre et maîtriser BreezingForms par des tutoriels et exemples, le tout en français

breezingforms.eddy-vh.com

Questions et réponses sur les forums de l'AFUJ

AFUJ

Special Offer

Summer Sale! All subscriptions at a special price!

Includes prio support, all of our current and future Joomla!® extensions and Joomla!® templates for the duration of your membership.

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!