The forum of the forums
Welcome to the Official Support Forum of Forumotion!

To take full advantage of everything offered by our forum, please log in if you are already a member, or join our community if you've not yet.



Create a free forum like this one.

Text changed depending on current month

View previous topic View next topic Go down

Solved Text changed depending on current month

Post by Kami-sama on June 18th 2017, 11: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, 6:17 pm; edited 1 time in total
avatar
Kami-sama
Forumember

Female Posts : 250
Reputation : 6
Language : English, Russian, German, Lithuanian
Location : Lithuania

http://hogas.huhohi.com/

Back to top Go down

Solved Re: Text changed depending on current month

Post by Wolfuryo on June 18th 2017, 11: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
Wolfuryo
Forumember

Posts : 240
Reputation : 59
Language : Romanian and English

http://board.realmsn.com

Back to top Go down

Solved Re: Text changed depending on current month

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

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

Female Posts : 250
Reputation : 6
Language : English, Russian, German, Lithuanian
Location : Lithuania

http://hogas.huhohi.com/

Back to top Go down

Solved Re: Text changed depending on current month

Post by Wolfuryo on June 19th 2017, 12:03 am

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

Posts : 240
Reputation : 59
Language : Romanian and English

http://board.realmsn.com

Back to top Go down

Solved Re: Text changed depending on current month

Post by Kami-sama on June 19th 2017, 12:18 am

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 ?
avatar
Kami-sama
Forumember

Female Posts : 250
Reputation : 6
Language : English, Russian, German, Lithuanian
Location : Lithuania

http://hogas.huhohi.com/

Back to top Go down

Solved Re: Text changed depending on current month

Post by Wolfuryo on June 20th 2017, 6: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
Wolfuryo
Forumember

Posts : 240
Reputation : 59
Language : Romanian and English

http://board.realmsn.com

Back to top Go down

Solved Re: Text changed depending on current month

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

Oh, this is GOLD. Thanks Smile

SOLVED
avatar
Kami-sama
Forumember

Female Posts : 250
Reputation : 6
Language : English, Russian, German, Lithuanian
Location : Lithuania

http://hogas.huhohi.com/

Back to top Go down

Solved Re: Text changed depending on current month

Post by SLGray on June 20th 2017, 6:18 pm

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


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

avatar
SLGray
Administrator
Administrator

Male Posts : 38737
Reputation : 2602
Language : English
Location : United States

http://classifiedads.forumotion.com/

Back to top Go down

View previous topic View next topic Back to top


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