Radom Text in Javascript

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kaustubh

    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
  • Evertjan.

    #2
    Re: Radom Text in Javascript

    Kaustubh wrote on 21 aug 2004 in comp.lang.javas cript:
    [color=blue]
    > 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 !
    >[/color]

    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)

    Comment

    • Martin Honnen

      #3
      Re: Radom Text in Javascript



      Kaustubh wrote:

      [color=blue]
      > 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 ![/color]

      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

      Comment

      • Kaustubh

        #4
        Re: Radom Text in Javascript

        Martin Honnen <mahotrash@yaho o.de> wrote in message news:<41275f82$ 0$7312$9b4e6d93 @newsread2.arco r-online.net>...[color=blue]
        > Kaustubh wrote:
        >
        >[color=green]
        > > 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 ![/color]
        >
        > 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>[/color]

        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

        Comment

        • Harag

          #5
          Re: Radom Text in Javascript

          On 21 Aug 2004 07:19:01 -0700, chris_loves@red iffmail.com (Kaustubh)
          wrote:
          [color=blue]
          >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[/color]


          depending on your DB do it on the db server.

          SQL Server 2k:

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

          HTH.

          Al.

          Comment

          Working...