473,320 Members | 1,900 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Random Quotes

Please can some-one help, I cannot get this to work.
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>Random Proverbs</title>
  4. <script type="text/javascript">
  5. <!-- HIDE FROM INCOMPATIBLE BROWSERS
  6. function changeQuote() {
  7.      var quotes = new array()
  8.      quotes[0] = "Laughter is the best medicine";
  9.      quotes[1] = "Never look a gift horse in the mouth";
  10.      quotes[2] = One good turn deserves another";
  11.      quotes[3] = "The early bird catches the worm";
  12.      quotes[4] = "Two is company, three is a crowd";
  13.      var newQuote = quotes[Math.round(Math.random()+quotes.length)];
  14.      document.quoteform.quote.value = newQuote[0];
  15. }
  16. var tick = setInterval("changeQuote()",3000);
  17. //STOP HIDING FROM INCOMPATIBLE BROWSERS -->
  18. </script>
  19. </head>
  20. <body>
  21. <form action="">
  22. <input type="text" size="50" name="quote" /><br/>
  23. </form>
  24. </body>
  25. </html>
  26.  
Jun 17 '07 #1
5 4053
gits
5,390 Expert Mod 4TB
hi ...

have a close look at the following (working) version of your code:

[HTML]<html>
<head>
<title>Random Proverbs</title>
<script type="text/javascript">
<!-- HIDE FROM INCOMPATIBLE BROWSERS
function changeQuote() {
var quotes = new Array()
quotes[0] = "Laughter is the best medicine";
quotes[1] = "Never look a gift horse in the mouth";
quotes[2] = "One good turn deserves another";
quotes[3] = "The early bird catches the worm";
quotes[4] = "Two is company, three is a crowd";

var newQuote = quotes[Math.round(Math.random()*(quotes.length-1))];
document.quoteform.quote.value = newQuote;
}
var tick = setInterval("changeQuote()",3000);
//STOP HIDING FROM INCOMPATIBLE BROWSERS -->
</script>
</head>
<body>
<form name="quoteform" action="">
<input type="text" size="50" name="quote" /><br/>
</form>
</body>
</html>
[/HTML]

you missed the name of the form, the rnd-number was wrong, newQuote is the array-value already, new Array()! (you may use [] for that) ... testing your script in firefox with the firebug-extension shows you most of the errors ...

kind regards ...
Jun 17 '07 #2
hi ...

have a close look at the following (working) version of your code:

[HTML]<html>
<head>
<title>Random Proverbs</title>
<script type="text/javascript">
<!-- HIDE FROM INCOMPATIBLE BROWSERS
function changeQuote() {
var quotes = new Array()
quotes[0] = "Laughter is the best medicine";
quotes[1] = "Never look a gift horse in the mouth";
quotes[2] = "One good turn deserves another";
quotes[3] = "The early bird catches the worm";
quotes[4] = "Two is company, three is a crowd";

var newQuote = quotes[Math.round(Math.random()*(quotes.length-1))];
document.quoteform.quote.value = newQuote;
}
var tick = setInterval("changeQuote()",3000);
//STOP HIDING FROM INCOMPATIBLE BROWSERS -->
</script>
</head>
<body>
<form name="quoteform" action="">
<input type="text" size="50" name="quote" /><br/>
</form>
</body>
</html>
[/HTML]

you missed the name of the form, the rnd-number was wrong, newQuote is the array-value already, new Array()! (you may use [] for that) ... testing your script in firefox with the firebug-extension shows you most of the errors ...

kind regards ...
Will do, thanks so much for the help, you have no idea how lost and frustrated I feel.
I found a download for Firefox, but have no idea how it works. Any tips as the help guide does not explain how to test one's code! ..... now I really sound doff, but this is all very new to me!
Jun 17 '07 #3
gits
5,390 Expert Mod 4TB
... firefox is a webbrowser based on the gecko-rendering-engine that is also used by netscape, mozilla, ... browsers. simply install it and use it like ms internet explorer ... it is nearly the same ... there is nothing more to mention about it ... you will see.

firefox is 'extensible' that means there are some extensions (consider it as kind of plugins) that you may download and install to it ... so go to firefox's menu and go to 'extras' -> 'add-ons' - a popup appears. you click 'extensions' on top of it ... and then you click 'download extensions' (right bottom corner) ... you will be directed to the extensions-download-page ... search for firebug and use the install-link provioded there ... that installs firebug ... and next time you start firefox you notice a little symbol in the right bottom corner of it ... click it and enable firebug ... you will see what to do! ... then load a page with your script ... perhaps with an error! ... you will see what firebug displays and thats the hint for the error ... play with firebug ... it will be of great help to you ... i promise ;)

kind regards ...
Jun 17 '07 #4
gits
5,390 Expert Mod 4TB
if you don't want to use firebug ... as an alternative you may use the javascript-console ... that already comes with firefox ... 'extras' -> 'Error-Console' ... there the javascript errors will be displayed too! ... its a little bit more simple ... ;)

kind regards ...
Jun 17 '07 #5
if you don't want to use firebug ... as an alternative you may use the javascript-console ... that already comes with firefox ... 'extras' -> 'Error-Console' ... there the javascript errors will be displayed too! ... its a little bit more simple ... ;)

kind regards ...
Will give it a try. Thanks again.
Jun 17 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: JDJones | last post by:
I'm using the following to generate a random quote on a PHP page and it works fine: <?php $quotes = 'quote #1'; $quotes = 'quote #2'; $quotes = 'quote #3'; $quotes = 'etc...'; srand...
4
by: Papa Legba | last post by:
I have huge page of links, to whcih I am currently adding. I would like to add a "random link" button which would parse the current page, extract all URLs then load a random link. Before I start...
23
by: Thomas Mlynarczyk | last post by:
I remember there is a programming language where you can initialize the random number generator, so that it can - if you want - give you the exactly same sequence of random numbers every time you...
4
by: lharby | last post by:
I'm hoping this is very simple. I am currently using a random quote generator on our intranet. I have 17 quotes, when I add in an 18th and change the makeArray number the code seems not to work....
1
by: -Art- (not Art) | last post by:
Is there a CSS solution to creating random quotes from a text or html file? TIA, -Art-
4
by: orbstra | last post by:
<?php //Variables //Quotes $quote = "'If at first you don't succeed; call it version 1.0' - T-Shirt"; $quote = "Microsoft: 'You`ve got questions. We've got dancing paperclips.' - Unknown";...
6
by: RTB | last post by:
I've been trying to replace my old PHP/iframe random quotes script with a PHP/javascript without success. http://www.just-quotes.com/wow/random.php <script...
4
by: Breana | last post by:
Ok, i want to make a sql statment select from a table, random quotes and display a random one each time the page is loaded! I got it to connect, but it keeps selecting all of them... <?php ...
3
by: keegan90 | last post by:
Hi there, first post so hope it goes well :) Im trying to generate statistics on which quote will be displayed each time i refresh the page. I've stored 10 famous quotes in the $famous_quotes...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.