Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Automatic calendar in text boxes when month is selected

Contributor ,
Nov 08, 2021 Nov 08, 2021

Hello everyone,

 

how can I create a calendar with TextBoxes so that the underlying text field always adds a day. Since I am unsure how and whether I can formulate it correctly, I have included the picture.

Would like to do the same with Adobe (TextBoxes instead of cells) as in Excel, is that possible? …if yes how?

Unbenannt3.jpg

 

Thanks everyone in advance

 

Nikolaos.

TOPICS
Create PDFs , How to , JavaScript
2.8K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
1 ACCEPTED SOLUTION
Community Expert ,
Nov 15, 2021 Nov 15, 2021

I don't understand why you changed my code. It would have worked fine. Here's the fixed version.

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 08, 2021 Nov 08, 2021

Yes. It's possible using a script.

So the user will enter the first date, right? What format will they be using?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 08, 2021 Nov 08, 2021

The user should only enter the month.

The format is German, otherwise the way it looks.

 

Thx 🙂

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 08, 2021 Nov 08, 2021

So they enter a number, between 1 and 12, then?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 08, 2021 Nov 08, 2021

If possible with a drop down field where the user can select the month would be best.

If not possible, I'll take what is possible 🙂

 

Thx

Nikolaos.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 08, 2021 Nov 08, 2021

Will it always be the current year?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 08, 2021 Nov 08, 2021

Yes, as long as I can change it with the script 🙂

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 08, 2021 Nov 08, 2021

I would be happy to receive a suggested solution.

 

... and thanks again in advance 🙂

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 09, 2021 Nov 09, 2021

OK, create a Drop-down field with all the month names (and a default value, something like "Select Month"), and 31 text fields called "Day.1", "Day.2", etc.

Then use this code as the custom Validation script of the drop-down (you'll need to adjust the first two arrays to have the correct day and month names to match the ones you're using):

 

 

var days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];

for (var i=1; i<=31; i++) this.getField("Day."+i).value = "";
if (event.value!=event.target.defaultValue) {
	var monthIndex = months.indexOf(event.value);
	var d = util.scand("m/d/yyyy", (monthIndex+1) + "/1/" + new Date().getFullYear());
	while (d.getMonth()==monthIndex) {
		this.getField("Day."+d.getDate()).value = d.getDate() + " - " + days[d.getDay()];
		d.setDate(d.getDate()+1);
	}
}

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 09, 2021 Nov 09, 2021

Thanks very much :-),

will try it out and give feedback.

 

Nikolaos.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 15, 2021 Nov 15, 2021

sorry for the late reply but my obligations have gotten out of hand.

I installed it as it is in your instructions.

Enter the months in the element list in the drop-down menu and enter the script

in the user-defined area (in the validation).

I labeled the days as described (Day.1, Say.2, etc.).

But after selecting the month in the preview, nothing appears.

I also changed the format to German, but didn't help either.

 

I'm doing something wrong, it would be nice if you could give me a tip.

 

*Adobe Acrobat Pro Dc - Version: 2015.006.30527

 

Thx in Advance,

 

Nikolaos.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 15, 2021 Nov 15, 2021

Are there any errors in the JS Console after you make the selection (Ctrl+J)?

Can you share the file?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 15, 2021 Nov 15, 2021

sry my mistake installed it again on a blank pdf page and it works ... great! 🙂 

The only thing I can't do is instead of example: to display the day, from this (1 - Freitag), in (01. Fr.).

 

I tried to change it with the underlying script (everything in blue), but without success.

How could I change it like that?

 

var days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];

var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];

 

for (var i=1; i<=31; i++) this.getField("Day."+i).value = "";

if (event.value!=event.target.defaultValue) {

                var monthIndex = months.indexOf(event.value);

                var d = util.scand("dd . ddd.", (monthIndex+1) + "/1/" + new Date().getFullYear());

                while (d.getMonth()==monthIndex) {

                               this.getField("Day."+d.getDate()).value = d.getDate() + " . " + days[d.getDay()];

                               d.setDate(d.getDate()+1);

                }

}

 

Thank you for your patience and time 🙂

 

Nikolaos.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 15, 2021 Nov 15, 2021

additionally here the file ... January works ... but february and the rest ... I probably have a mistake somewhere.

 

thx 🙂

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 15, 2021 Nov 15, 2021

I don't understand why you changed my code. It would have worked fine. Here's the fixed version.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 18, 2021 Nov 18, 2021

A late and small last additional question has arisen 🙂

I tried it myself but without success.

How can I put the existing code that you sent me into a fixed year.

 

Example that it is for 2022 or 2023, depending on what you want?

 

Thanks 🙂

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 18, 2021 Nov 18, 2021
LATEST

Change:

new Date().getFullYear()

To:

"2022"

or

"2023"

etc.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 15, 2021 Nov 15, 2021

Now it has sparked! 🙂

sorry for the annoyance, everything worked wonderfully

... only the one with 01 instead of 1 (day: 01,02,03,04,05,06,07,08,09,10, etc.).

Your template script is SUPER! 🙂 🙂

Attached are the changes (java script with changes) that I have made so far, it is suitable for German speakers.

 

I would be happy if you could give me a suggestion for a solution to insert the zero before the individual numbers. 

 

var days = ["So.", "Mo.", "Di.", "Mi.", "Do.", "Fr.", "Sa."];
var months = ["Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"];

for (var i=1; i<=31; i++) this.getField("Day."+i).value = "";
if (event.value!=event.target.defaultValue) {
	var monthIndex = months.indexOf(event.value);
	var d = util.scand("m/d/yyyy", (monthIndex+1) + "/1/" + new Date().getFullYear());
	while (d.getMonth()==monthIndex) {
		this.getField("Day."+d.getDate()).value = d.getDate() + " - " + days[d.getDay()];
		d.setDate(d.getDate()+1);
	}
}

 

 

Thank you for everything, especially for the patience and time you have invested in me.

 

Nikolaos.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 15, 2021 Nov 15, 2021

Change this line:

 

this.getField("Day."+d.getDate()).value = d.getDate() + " - " + days[d.getDay()];

 

To this:

 

var dateString = d.getDate()<10 ? "0"+d.getDate() : d.getDate();
this.getField("Day."+d.getDate()).value = dateString + " - " + days[d.getDay()];

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 15, 2021 Nov 15, 2021

A dream! thanks

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines