The forum of the forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Text changed depending on current month

2 posters

Go down

Solved Text changed depending on current month

Post by Kami-sama June 18th 2017, 9:05 pm

Technical Details


Forum version : #phpBB2
Position : Founder
Concerned browser(s) : Google Chrome
Who the problem concerns : Yourself
Forum link : http://hogas.huhohi.com/

Description of problem

Hey guys!

Basically, lets say I have a div on all of my pages:
Code:
<div class="example1">text</div>

Depending on current month, I want the text to change.

For example:
January:
Code:
<div class="example1">text 1</div>

February:
Code:
<div class="example1">text 2</div>

March:
Code:
<div class="example1">text 3</div>
...

I am aware how to replace text wit scripts using IF clause.
I am not sure how to take current month as variable...
Any ideas, suggestions?


Last edited by Kami-sama on June 20th 2017, 4:17 pm; edited 1 time in total
Kami-sama
Kami-sama
Forumember

Female Posts : 407
Reputation : 12
Language : EN, RU, DE, LT
Location : Lithuania

http://hogas.huhohi.com/

Back to top Go down

Solved Re: Text changed depending on current month

Post by Guest June 18th 2017, 9:30 pm

Hi,

This should do it:
Code:

window.onload=function(){
var elem=$(selector);
var texts=[
"Text",
"Text",
"Text",
"Text",
"Text",
"Text",
"Text",
"Text",
"Text",
"Text",
"Text",
"Text"
];
var date=new Date();
var month=date.getMonth();
elem.text(texts[month]);
};

Edit:You have to replace selector(from
Code:
$(selector)
with the class or id of the element you want the texts to be shown into.
avatar
Guest
Guest


Back to top Go down

Solved Re: Text changed depending on current month

Post by Kami-sama June 18th 2017, 9:37 pm

mmm. does not seam to work. I only replaced this, so it should work....
Code:
var elem=$(.example1);
Kami-sama
Kami-sama
Forumember

Female Posts : 407
Reputation : 12
Language : EN, RU, DE, LT
Location : Lithuania

http://hogas.huhohi.com/

Back to top Go down

Solved Re: Text changed depending on current month

Post by Guest June 18th 2017, 10:03 pm

You forgot surrounding the selector with quotes. It should be like this:
Code:
var elem=$(".example1");
.
avatar
Guest
Guest


Back to top Go down

Solved Re: Text changed depending on current month

Post by Kami-sama June 18th 2017, 10:18 pm

Oh, right Very Happy hahahah. I did notice it saying "syntax error" XD
All good! Thank you.
Will this work also wit getTime and getYear ?
Kami-sama
Kami-sama
Forumember

Female Posts : 407
Reputation : 12
Language : EN, RU, DE, LT
Location : Lithuania

http://hogas.huhohi.com/

Back to top Go down

Solved Re: Text changed depending on current month

Post by Guest June 20th 2017, 4:00 pm

Take a look here to find out more about the date methods in javascript:https://www.w3schools.com/js/js_date_methods.asp
This could be useful too:https://www.w3schools.com/jsref/jsref_obj_date.asp
avatar
Guest
Guest


Back to top Go down

Solved Re: Text changed depending on current month

Post by Kami-sama June 20th 2017, 4:17 pm

Oh, this is GOLD. Thanks Smile

SOLVED
Kami-sama
Kami-sama
Forumember

Female Posts : 407
Reputation : 12
Language : EN, RU, DE, LT
Location : Lithuania

http://hogas.huhohi.com/

Back to top Go down

Solved Re: Text changed depending on current month

Post by SLGray June 20th 2017, 4:18 pm

Problem solved & topic archived.
Please read our forum rules:  ESF General Rules


Text changed depending on current month Slgray10

When your topic has been solved, ensure you mark the topic solved.
Never post your email in public.
SLGray
SLGray
Administrator
Administrator

Male Posts : 51463
Reputation : 3519
Language : English
Location : United States

https://forumsclub.com/gc/128-link-directory/

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum