www.webdeveloper.com
Results 1 to 2 of 2

Thread: How to add a button in this program

  1. #1
    Join Date
    Jun 2014
    Posts
    2

    How to add a button in this program

    This program generates random text from a text file
    how to add button in this i tried not working,,wer to add can u pls help mee
    Code:
    <html>
    <head>
    <script>
    var request = new XMLHttpRequest();
    request.onload = function() {
    // get the file contents
    var fileContent = this.responseText;
    // split into lines
    var fileContentLines = fileContent.split( '\n' );
    // get a random index (line number)
    var randomLineIndex = Math.floor( Math.random() * fileContentLines.length );
    // extract the value
    var randomLine = fileContentLines[ randomLineIndex ];
    
    // add the random line in a div
    document.getElementById( 'random-phrase' ).innerHTML = randomLine;
    };
    request.open( 'GET', 'animals.txt', true );
    request.send(); 
    </script>
    </head>
    <body>
    <div id="random-phrase"></div>
    </body>
    </html>
    Last edited by jedaisoul; 06-14-2014 at 01:19 PM. Reason: code tags added

  2. #2
    Join Date
    Mar 2012
    Posts
    1,509
    What is the button supposed to do???

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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