Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8136333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T10:43:44+00:00 2026-06-06T10:43:44+00:00

I am working on my own Lorem Ipsum generator, with the added bonus of

  • 0

I am working on my own Lorem Ipsum generator, with the added bonus of generating the corresponding HTML formatting code in a box beside it.

So, the paragraph is generated via this button

<button id="generate" type="button" onclick="LoremIpsumRandom()">1 Paragraph</button>

and is generated here
<p id="textarea"></p>

function LoremIpsumRandom()
{
    //global to store previous random int
     _oldInt = null;

var pickRandom = function(paragraphArray)
    {
        //random index of paragraphArray
        var randomInt = Math.floor(Math.random()*paragraphArray.length);
        //ensure random integer isn't the same as last
        if(randomInt == _oldInt)
            pickRandom(paragraphArray);
        else{
            _oldInt = randomInt;
            return paragraphArray[randomInt];
            }
    }
    //your lorem ipsum paragraphs
    var paragraphArray =     [
                            "Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.", 
                            "Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt.", 
                            "Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem.", 
                            "Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur?", "Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?", 
                            "At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga.", 
                            "Et harum quidem rerum facilis est et expedita distinctio.", "Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus.", 
                            "Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae.", 
                            "Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat."
                            ];  

//update element content (e.g. `<div>` with paragraph
    document.getElementById("textarea").innerHTML = pickRandom(paragraphArray);
    //document.getElementById("textarea-code").innerText = pickRandom("&lt;P&gt;" + (paragraphArray) + "&lt;&#47;P&gt;");



}

No point including the CSS to be honest – it’s just standard text boxes and auto-generated buttons.

So, the issue is that although I can generate the normal paragraph in the id=”textarea” section, I want to be able to generate a raw HTML version as well (with the paragraph and line breaks code being shown.) So far, I’ve been able to generate the raw HTML with no issues, but when I added @pixelbobby ‘s section (which makes sure that when a sentence is selected, the next selection won’t be the same, as true randomness can sometimes generate), the code doesn’t work. In some instances, it’s generated the raw HTML, but the generated paragraph is a different one.

The other functions (generating lists, multi-paragraphed sections and multi-levelled lists) utilise the raw HTML and output correctly, and it all runs smoothly. The raw HTML is always outputted to
<p id="textarea-code"></p>
which is next to the first textarea section.

Can someone tell me how I can modify the script so that the raw HTML part of the script generates the same paragraph as the result of the pickRandom(paragraphArray)

So,
This – document.getElementById("textarea-code").innerText = pickRandom("&lt;P&gt;" + (paragraphArray) + "&lt;&#47;P&gt;");
needs to be the same as – document.getElementById("textarea").innerHTML = pickRandom(paragraphArray);
but with the raw HTML specified in the pickRandom() part of the line.

Can anyone help?

Thanks 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T10:43:46+00:00Added an answer on June 6, 2026 at 10:43 am

    You can save the result of pickRandom(paragraphArray) in a variable and use it twice:

    var randomParagraph = pickRandom(paragraphArray); //save the result of pickRandom
    
    document.getElementById("textarea").innerHTML = randomParagraph;
    document.getElementById("textarea-code").innerText = "&lt;P&gt;" + randomParagraph + "&lt;&#47;P&gt;");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working at my own signature generator. How to show in-fly generated image without
I copy-pasted this code from my own previous working document, so I know the
I'm working on my own text editor in silverlight. I made different functions to
I've been working on my own django based blog (like everyone, I know) to
I am currently working on my own implementation of a tab bar for a
I am developing an MFC application. I am working with my own .bmp image
I'm working on my very own CMS. I put the latest updates of the
I'm working through SICP on my own, so I don't have an instructor to
I'm working on writing my own string class and am having trouble with overloading
I am working with Integration of multiple applications which is using their own databases.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.