www.webdeveloper.com
Results 1 to 7 of 7

Thread: How to: javascript needed

  1. #1
    Join Date
    Jun 2014
    Posts
    3

    Question How to: javascript needed

    How to: javascript needed
    script displays a random text from a list,
    end of random text displayed the button answer,
    Click on the button shown in response to the random text below the corresponding text (answer)

    was something in the mind like:
    Code:
    <html>
    <body bgcolor="black" text="#CCCCCC" link="blue" vlink="purple" alink="red">
    </body><table border="1" width="284" align="center">
    <tr>
    <td width="274" height="68">
    
    <p>
    
    <script language="JavaScript">
    <!--
    function random_text()
    {};
    var random_text = new random_text();
    // Set the number of text strings to zero to start
    var number = 0;
    // Incremental list of all possible Text
    random_text[number++] = "<font color='#CCCCCC'> Random Txt #1</font>"
    random_text[number++] = "<font color='#CCCCCC'> Random Txt #2</font>"
    random_text[number++] = "<font color='#CCCCCC'> Random Txt #3</font>"
    
    var random_number = Math.floor(Math.random() * number);
    document.write(random_text[random_number]);
    -->
    
    
    </script>
    </p>
    </td>
    </tr>
    </table>
    </html>
    plus:
    http://www.dynamicdrive.com/dynamici...edcollapse.htm

    ...a combination of the two scripts
    Last edited by jedaisoul; 06-06-2014 at 05:34 PM.

  2. #2
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,437
    Several problems jump out...

    1. How old is this script that you copied and modified? <script language="JavaScript"> has been deprecated for awhile now.
    2. You do not need <! -- and --> for comments within JS in modern browsers.
    3. Your "random_text()" function has no actions to perform, ie; no function.
    4. 'random_text[ ] array is not defined.
    5. You are using "document.write()", but you will find that you cannot modify the page after it has been rendered.
    6. Your script and table are outside the <body> tags of the HTML document.
    7. Your link to combine with your 1st attempt is broken.

    It's an attempt, but you will need to go back to the drawing board for this version.

  3. #3
    Join Date
    Jun 2014
    Posts
    3
    Yes, I know it's an old script. (I'm just beginner to writing scripts)
    it is working on a separate HTML page. (IE, FF, Android)
    do not need a big system files.

    Just need to build a simple separate HTML page
    ...a combination of the two scripts.
    the rest of the design is simple

  4. #4
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,437
    Fix the simple problems first so as to not distract from the real problem.

  5. #5
    Join Date
    Jun 2014
    Posts
    3
    <html>

    <head>
    <title>No title</title>
    </head>

    <body bgcolor="black" text="#CCCCCC" link="blue" vlink="purple" alink="red">
    <table border="1" width="284" align="center">
    <p>&nbsp;</p>
    <tr>
    <td width="275" height="70">
    <script language="JavaScript">
    <!--
    function random_text()
    {};
    var random_text = new random_text();
    // Set the number of text strings to zero to start
    var number = 0;
    // Incremental list of all possible Text
    random_text[number++] = "<font color='#CCCCCC'> Random Txt #1</font>"
    random_text[number++] = "<font color='#CCCCCC'> Random Txt #2</font>"
    random_text[number++] = "<font color='#CCCCCC'> Random Txt #3</font>"

    var random_number = Math.floor(Math.random() * number);
    document.write(random_text[random_number]);
    -->
    </script>
    </td>
    </tr>
    </table>
    </body>
    </html>



    +http://www.dynamicdrive.com/dynamici...edcollapse.htm

  6. #6
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,506
    Please use forum tags, it helps.

    HTML Code:
    <html>
    
    <head>
    <title>No title</title>
    </head>
    
    <body bgcolor="black" text="#CCCCCC" link="blue" vlink="purple" alink="red">
    <table border="1" width="284" align="center">
    <p>&nbsp;</p>
    <tr>
    <td width="275" height="70">
    <script language="JavaScript">
    <!--
    function random_text()
    {};
    var random_text = new random_text();
    // Set the number of text strings to zero to start
    var number = 0;
    // Incremental list of all possible Text
    random_text[number++] = "<font color='#CCCCCC'> Random Txt #1</font>"
    random_text[number++] = "<font color='#CCCCCC'> Random Txt #2</font>"
    random_text[number++] = "<font color='#CCCCCC'> Random Txt #3</font>"
    
    var random_number = Math.floor(Math.random() * number);
    document.write(random_text[random_number]);
    -->
    </script>
    </td>
    </tr>
    </table>
    </body>
    </html>
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  7. #7
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,437

    Lightbulb

    And fix your HTML and deprecated JS and drop in some CSS ...
    Code:
    <!doctype html>
    <html>
    <meta charset="utf-8">
    <head>
    <title>No title</title>
    
    <style type="text/css">
     #msgHolder { position:absolute; top:100px; left:400px; }
     #msg { color="#CCCCCC";  width:275px;  height:70px;  border:5px double #cccccc;  text-align:center; }
    </style>
    
    </head>
    
    <body bgcolor="black" text="#CCCCCC" link="blue" vlink="purple" alink="red">
    <button onclick="newMessage()">For Testing Purposes Only</button> <p>
    <div id="msgHolder">
     <div id="msg">YOUR TEXT HERE</div>
    </div>
    
    <script type="text/javascript">
    var random_text = [];
    
    function create_random_text() {
      var number = 0;   // Set the number of text strings to zero to start
    // Incremental list of all possible Text
      random_text[number++] = "Random Txt #1<br>and more";
      random_text[number++] = "Random Txt #2<br>and more";
      random_text[number++] = "Random Txt #3<br>and more";
      random_text[number++] = "Random Txt #4<br>and more";
      random_text[number++] = "Random Txt #5<br>and more";
      random_text[number++] = "Random Txt #6<br>and more";
      random_text[number++] = "Random Txt #7<br>and more";
      random_text[number++] = "Random Txt #8<br>and more";
      random_text[number++] = "Random Txt #9<br>and more";
    }
    
    function newMessage() {
      var random_number = Math.floor(Math.random() * random_text.length);
      document.getElementById('msg').innerHTML = random_text[random_number];
    }
    
    window.onload = function() {
      create_random_text();
      newMessage();
    }
    </script>
    
    </body>
    </html>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles