473,395 Members | 1,468 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,395 software developers and data experts.

Radom Text in Javascript

Well Hie,
i need all you genius guys help. Well i have databse of quotes in TXT
format i want the javascript which ll radomize that database means
everytime when user come on my page then script ll pick up one
sentence from data base and show it but i want diff sentence at each
visit i have done in ASP i want that in JAVA script please let me have
you guys Help !
Thanks
Jul 23 '05 #1
4 1594
Kaustubh wrote on 21 aug 2004 in comp.lang.javascript:
i need all you genius guys help. Well i have databse of quotes in TXT
format i want the javascript which ll radomize that database means
everytime when user come on my page then script ll pick up one
sentence from data base and show it but i want diff sentence at each
visit i have done in ASP i want that in JAVA script please let me have
you guys Help !


Simple, as you can do serverside ASP in Javascript.

But as you seem [I suppose] to have done this in ASP under vbscript,
why the change?

If however you want to do this in clientside javascript,
what database would you suggest you van reach?
You cannot access a serverside database with clientside script.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 23 '05 #2


Kaustubh wrote:

i need all you genius guys help. Well i have databse of quotes in TXT
format i want the javascript which ll radomize that database means
everytime when user come on my page then script ll pick up one
sentence from data base and show it but i want diff sentence at each
visit i have done in ASP i want that in JAVA script please let me have
you guys Help !


I think you can even use SQL to select a random row/record from a data
base table so why do you want to use client-side script to achieve that?
Solve that on the server and there is no problem with clients having
script disabled or not supporting script.

If you really want to use client-side script create an array with the
quotes and use a random index into the array:

<html lang="en">
<head>
<title>random quotes</title>
<script type="text/javascript">
var quotes = [
'Kibology for all.',
'All for Kibology.',
'Kibology rules.'
];
var randomIndex = Math.floor(Math.random() * quotes.length);
var randomQuote = quotes[randomIndex];
</script>
</head>
<body>
<p>
<script type="text/javascript">
document.write(randomQuote);
</script>
</p>
</body>
</html>

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #3
Martin Honnen <ma*******@yahoo.de> wrote in message news:<41**********************@newsread2.arcor-online.net>...
Kaustubh wrote:

i need all you genius guys help. Well i have databse of quotes in TXT
format i want the javascript which ll radomize that database means
everytime when user come on my page then script ll pick up one
sentence from data base and show it but i want diff sentence at each
visit i have done in ASP i want that in JAVA script please let me have
you guys Help !


I think you can even use SQL to select a random row/record from a data
base table so why do you want to use client-side script to achieve that?
Solve that on the server and there is no problem with clients having
script disabled or not supporting script.

If you really want to use client-side script create an array with the
quotes and use a random index into the array:

<html lang="en">
<head>
<title>random quotes</title>
<script type="text/javascript">
var quotes = [
'Kibology for all.',
'All for Kibology.',
'Kibology rules.'
];
var randomIndex = Math.floor(Math.random() * quotes.length);
var randomQuote = quotes[randomIndex];
</script>
</head>
<body>
<p>
<script type="text/javascript">
document.write(randomQuote);
</script>
</p>
</body>
</html>


Remember i have txt formal which contain all quotes i cant write each
quote in java script to view each time i just want script open txt
file and read the diff quotes on each time of visit . actually my
friends Linux webserver does nto support ASP that is why i want to do
this .. please tell me just want to read one quote each time and show
it look in http://kcool.cjb.net i want that each quote see below
thought vitamin Box.. look at it
Jul 23 '05 #4
On 21 Aug 2004 07:19:01 -0700, ch*********@rediffmail.com (Kaustubh)
wrote:
Well Hie,
i need all you genius guys help. Well i have databse of quotes in TXT
format i want the javascript which ll radomize that database means
everytime when user come on my page then script ll pick up one
sentence from data base and show it but i want diff sentence at each
visit i have done in ASP i want that in JAVA script please let me have
you guys Help !
Thanks

depending on your DB do it on the db server.

SQL Server 2k:

SELECT TOP 1 [quote] FROM MyQuotesTable ORDER BY NEWID()

HTH.

Al.
Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Randell D. | last post by:
Folks, I'm still learning javascript - I've invested in a couple of books and reading online as much as possible. I'm pretty sure what I am suggesting is possible though I'm trying to weigh up...
27
by: C Gillespie | last post by:
Dear All, Hopefully I have a simple problem. Basically, I just want to alter some text with JS. Here is some of my test code: <snip> <script type="text/javascript"> var tmp='a';
19
by: dmiller23462 | last post by:
Hi guys....I have absolutely NO IDEA what I'm doing with Javascript but my end result is I need two text boxes to stay hidden until a particular option is selected....I've cobbled together the...
1
by: IkBenHet | last post by:
Hello, I found this script to create a simple rich text form (http://programmabilities.com/xml/index.php?id=17): <html> <head> <title>Rich Text Editor</title> </head> <body>
2
by: charlie_M | last post by:
I have the following code: <script type=text/javascript> function hide_tooltip(){ var hp = document.getElementById("tooltipper"); hp.style.left=0; hp.style.top=0; hp.style.width=1;...
3
by: jweinberg1975 | last post by:
I would like for users to be able to select from a small number of options that come from a little drop down menu which then closes. .....
9
by: Erwin Moller | last post by:
Hi, Can anybody comment on this? In comp.lang.php I advised somebody to skip using: <script language="javascript"> and use: <script type="text/javascript"> And mr. Dunlop gave this response:
12
by: tim | last post by:
I am using foldoutmenu 3 and am having problems with viewing my menus in firefox. On my sub3 menus i have more than one line of text in some places. firefox does not recognise that there is more...
2
by: hermitking | last post by:
i jsut started to learn vb 2005 at school and i need to know a how to make a value be radom
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.