Saturday, May 8, 2010

Quote of the day - Code in Javascript


I could not find quote of the day code which could support up to 365 quotes. So my friend J.M. developed a code. We re thank full to him for developing this code for free. We are happy to release Quote of the day code.


1. Quotes are parsed and so that no quote is missed.

2. Quotes refresh daily and not on browser tab refresh.

3. Upto 365 quotes. So new quote for a year.

4. Contains date script.

5. Fully customizable.

Troubleshooting / Points to consider while uploading the code.

1. Do not use special characters. They may / may not be supported.

2. Do not use the characters like Opening and closing double quotes (" ") and semicolon (;) since they are used by the codes.

e.g. if you use this quote

The Mother said, "She devotes her energy to bring up . passing through all these experiences; so then . done"

Then the code will look like

Quotes[1]= " The Mother said, "She devotes her energy to bring up . passing through all these experiences; so then . done" ";

a. As you can see there are two opening and two closing quotes.

b. Again the semi colon is repeated twice (one in the quote and another at the end (needed to complete the line of code)

This will not allow the code to work ad nothing will be displayed.

So change it to

Quotes[1]= " The Mother said, 'She devotes her energy to bring up . passing through all these experiences, so then . done' ";

Here double opening and closing quotes ("") are replaced by single ones ('') and semicolon (;) by comma (,).

The best and fastest way according to me is to copy the quotes in word processer like MS word. Then find and replace all ( " ) by ( '), ( " ) by ( ') and ( ; ) by ( , ).

c. If the code is still not displayed, then remove other special characters like underscore (_), in short, make your quote in simple plain text and check if it works.

Please find code for Quote of the day.


<p><font face="Trebuchet MS" color="#800000" size="2">
<!-- date script starts -->
<script type="text/javascript">
var d=new Date()
var weekday=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
var monthname=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
document.write(weekday[d.getDay()] + ", ")
document.write(monthname[d.getMonth()] + " ")
document.write(d.getDate() + " ")

<!-- date script ends ->
<!- QOTD Script developed by J.M. for starts -->

<script type="text/javascript">
var today= new Date();
var first = new Date(today.getFullYear(), 0, 1);
var day = Math.round(((today - first) / 86400000), 0);
var numquotes = 5;
Quotes = new Array(numquotes+1);
Quotes[1]= " Once you know maya, it runs away, it can no more influence you.";
Quotes[2]= " Only god is truth, everything else is false";
Quotes[3]= " The one you has created the laws of nature also has the powers to change, replace or break the laws of nature";
Quotes[4]= " He who has faith has everything, and he who lacks faith lacks everything. It is the faith in the name of the Lord that works wonders, FAITH IS LIFE & DOUBT IS DEATH.";
Quotes[5]= " You can also ask for Brahma Jnana to divine mother.";
var ran = (day % numquotes) + 1;
document.write(Quotes[ran] + '<p style="text-align: right"><i>' +  '</i></p>');


<!-- end of OFTD script by J.M. -->
<p><font face="Trebuchet MS" color="#800000" size="2"><p><i>- Sri Ramakrishna</i></p></font></p>

How to use the code

1. The lines marked in green are the comments, which the makes no difference to a browser but makes it easier for us to identify the codes.

2.  The date script contains

var monthname=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")

You can change ( Sunday ) to ( Sun ) and/or ( Jan ) to ( January )

If you do not wish to add date, then just delete lines starting from (including)

<!-- date script starts ->

<!-- date script ends ->

3. Change the number of quotes.


var numquotes = 5;

change 5 to any number. here 5 is any number 'n'

make sure that 'n' mentioned in var numquotes and the last number in square bracket after ( Quotes ) is the same.

Quotes[5]= " You can also ask for Brahma Jnana to divine mother.";

4.  I Have created the quote code which has only one saint. So Instead of adding the name in each quote I have added it in the last

<p><font face="Trebuchet MS" color="#800000" size="2"><p><i>- Sri Ramakrishna</i></p></font></p>

Here  ( - Sri Ramakrishna ) can be changed.

If you want to display quotes by more than one saints, then in each quote, the name has to be added manually.


Quotes[5]= " You can also ask for Brahma Jnana to divine mother. - Sri Ramakrishna";

5. If you have some knowledge of CSS, then you can change way this script is displayed.

Hope you will find this script / code useful.

Hari Aum



ashokv said...

I grabbed that code.I am getting just one Quote a day .


Yes, The quote only changes after 24 hours. So you get new quote every day.

It does not change with page refresh

If you want quotes from multiple authors, or more than one (n) quotes at a time, than you will need to repeat the entire code with custom quotes (n) times.

Chinttan said...

I have pasted in my html page it worked. but when i added 30 more qutoes and at the same time i changed var numquotes to = 31, then nothing appears it only takes 6 var numquotes.
Is there anything that the quote should be small or there is a limitation of characters in any quote.


Indiaspirituality Amrut said...

I do not think there is any limitation to the length of quote, but as said above there should be no special character like semi colon or double quotes.

Please check 7th quote, it might have some special character.

also keep n = number of quotes. I have added 365 quotes and they are all working fine.

This may sound stupid, but here is what I do it. It really speeds up the work. When our intellect surrenders, there is some stupid mistake, so best is to go to basics.

1. Open the quotes in word file.

2. Remove numbering if present

3.Use Find All and Replace All.

a. Find double quotes {"} and replace it with single quote {'}

b. Find semi colon {;} and replace it with comma {,} or colon {:} whatever you like.

4. copy paste in notepad or notepad++. Notepad will keep one quote in one line, irrespective of length of quote. Notepad++ also has numbering for easy reference.

5. Add opening and closing syntax.

a. copy

Quotes[1]= "

pressed down arrow key and then home key and then ctrl + v

Quotes[1]= " abcd.
Quotes[1]= " efgh
Quotes[1]= "mmnt rthy

then change [1] number to required number.

press end and then add


copy it, press down arrow key, press end and then control + v

Note: full stop is not causing problem

Still if you do not get it, if you do not mind, please email me at indiaspirituality[at]

If you want my sample of quote, I can give you Rumi's quote which has 365 quotes.

Indiaspirituality Amrut said...

as far as character limitation is concerned, I have following quote containing 258 words and 1397 characters with spacing displaying correctly

Quotes[228]="Ah, how much I prayed for them, wept for them before the Master! That is how they have today a monastery and such other things by his grace. After the Master's passing away, his children renounced the world and gathered together at one place for a few days. Thereafter one by one they left and were wandering here and there. Then I felt very sad. I began to pray to the Master: 'O Lord, you have come, performed your divine play with these few people, enjoyed yourself and gone away. Is everything finished with that? If so, what was the need for you to come, taking so much trouble? I saw in Kasi and Vrindaban so many Sadhus who live by begging and dwell under the shade of trees, wandering at will. There never was any dearth of such Sadhus. I cannot bear to see my children, who have left everything and come away taking your name, wandering around for the sake of a few handfuls of food. It is my prayer that those who come away in your name should not lack food and clothing, that all of them stay together, taking you, our memory and your teachings for their support; and that those who are scorched by the miseries of worldly existence come to them and obtain peace and solace by learning of your life and teachings. This was the purpose of your advent. It wrings my heart that they should wander here and there shelter less. Since that time, slowly Naren built up all this.";

Indiaspirituality Amrut said...

I have also changed var numquotes = 365; in Sri Sarada Maa quotes which has 320 quotes. It's displaying correctly.

I hope this helps.

Featured Post

Introduction of Madhusūdana Sarasvatī’s Gūḍārtha Dīpikā, a unique commentary on Bhagavad Gītā

Update: 01/08/2016. Verses 8 a nd 9 are corrected. 'Thou' is correctly translated to 'tvam' and 't hat...