Daily Quote with javascript

570 views
Skip to first unread message

Allister

unread,
Nov 21, 2010, 9:54:08 AM11/21/10
to phonegap
Hi there - hope someone can point me in the right direction.

I've set up a javascript Daily Quote script which works up to the
point of showing the quote for the day the app is launched after it is
built, but then seems to be cached and wont change on the next day.

In my header I have the array source (quote.js) which is local on the
device and has:
var quote = new Array();
Stamp = new Date();
date = Stamp.getDate();
quote[0]="first quote";
quote[1]="second quote";

…..down to

quote[31]="31st quote";

In the html I have:
<script language="JavaScript">
<!--
document.write(quote[date]);
//-->
</script>

At first I thought it was caching in the manifest, but I took out the
quote.js entry and it doesn't seem to help. It could also be my
understanding of javascript.

Any help gratefully received.
Allister

SK15 ®

unread,
Nov 21, 2010, 10:33:48 AM11/21/10
to phonegap
The program is probably like this open in the memory of the apparel
when he opens he only comes back to the previous state and not opening
a new call.
What comes me now the mind it is to do JavaScript to constantly be
modernized to verify the date and to show in the screen...

Something like that (even so I don't know it is angered to work):

<b id="texts">&nbsp;</b>

<script type="text/javascript">
var quote = new Array();
quote[0]=""; quote[1]="1"; quote[2]="2"; quote[3]="3"; quote[4]="4";
quote[5]="5";
quote[6]="6"; quote[7]="7"; quote[8]="8"; quote[9]="9";
quote[10]="10"; quote[11]="11";
quote[12]="12"; quote[13]="13"; quote[14]="14"; quote[15]="15";
quote[16]="16"; quote[17]="17";
quote[18]="18"; quote[19]="19"; quote[20]="20"; quote[21]="21";
quote[22]="22"; quote[23]="23";
quote[24]="24"; quote[25]="25"; quote[25]="25"; quote[27]="25";
quote[28]="25"; quote[29]="25";
quote[30]="25"; quote[31]="31";

function LoadDate() {
var stamp = new Date();
date = stamp.getDate();
document.getElementById("texts").innerHTML = quote[date];
setTimeout("LoadDate();", 1000);
}

window.onload = LoadDate;
</script>

Allister

unread,
Nov 21, 2010, 11:28:41 AM11/21/10
to phonegap
HI there - thanks for getting back to me so promptly on this!

Can you just clarify what should be part of the .js file and what
should be in the html. I want to separate all the quotes from the html
as it gets unwieldy. Up till now I (other than reference to the array
source in the header, I only have
<script language="JavaScript">
<!--
document.write(quote[date]);
//-->
</script>
in the body of the html.

What of your code needs to go into the array and what into the html,
calling and writing out the array data?
THanks
Allister

Cristian Bullokles

unread,
Nov 21, 2010, 2:31:23 PM11/21/10
to Allister, phonegap
Create an DailyQuotes object in a separate file


DailyQuotes.js

function DailyQuotes() {
      var quotes = new Array();
      quotes[0] = "quote';
      quotes[1] = "quote'; 
 
     quotes[X] = "quote';
}

DailyQuotes.prototype.getCurrentQuote = function(){
     today = Date.... //
      this.getQuote( today );
}

DailyQuotes.prototype.getQuote = function(day ){
      return quotes[day];
}

and then in html

dailyQuotes = new DialyQuotes();

var quoteOfTheDay = dailyQuotes.getCurrentQuote();


Regards
Cristian


--
You received this message because you are subscribed to the Google
Groups "phonegap" group.
To post to this group, send email to phon...@googlegroups.com
To unsubscribe from this group, send email to
phonegap+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/phonegap?hl=en?hl=en

For more info on PhoneGap or to download the code go to www.phonegap.com

Allister

unread,
Nov 22, 2010, 2:55:03 AM11/22/10
to phonegap
Hi Christian - thanks for this.

Unfortunately I'm still having problems in getting it to fire up and I
get a parse error from the DailyQuotes.js file

In the html, does it matter that there is both DailyQuotes and
dailyQuotes (which I assume you meant to be in the body), and does it
have to be wrapped in the JavaScript tags in the html body? I assume I
reference the DailyQuotes.js file in JavaScript in the header still?

Thanks for all your help in getting me sorted!
Warm regards,
Allister



On Nov 21, 7:31 pm, Cristian Bullokles <cristian.bullok...@gmail.com>
wrote:
> Create an DailyQuotes object in a separate file
>
> DailyQuotes.js
>
> function DailyQuotes() {
>       var quotes = new Array();
>       quotes[0] = "quote';
>       quotes[1] = "quote';
>
>      quotes[X] = "quote';
>
> }
>
> DailyQuotes.prototype.getCurrentQuote = function(){
>      today = Date.... //
>       this.getQuote( today );
>
> }
>
> DailyQuotes.prototype.getQuote = function(day ){
>       return quotes[day];
>
> }
>
> and then in html
>
> dailyQuotes = new DialyQuotes();
>
> var quoteOfTheDay = dailyQuotes.getCurrentQuote();
>
> Regards
> Cristian
>
> > phonegap+u...@googlegroups.com<phonegap%2Bunsu...@googlegroups.com>
Reply all
Reply to author
Forward
0 new messages