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

  • SEARCH
  • Home
  • 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 8582517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:18:39+00:00 2026-06-11T21:18:39+00:00

I need to make a simple Javascript converter, which would turn <textarea> input into

  • 0

I need to make a simple Javascript converter, which would turn <textarea> input into html-formatted list.

This is how a sample input would look:

Brand: Brand1
  Model1 /Model2 /Model3 /Model4 /Model5 /Model6 /
Brand: Brand2
  Model1 /Model2 /Model3 /Model4 /Model5 /Model6 /

And this would be the html after conversion:

<h3>Brand1</h3>
<ul>
  <li>Model1</li>
  <li>Model2</li>
  <li>Model3</li>
  <li>Model4</li>
  <li>Model5</li>
  <li>Model6</li>
</ul>
<h3>Brand2</h3>
<ul>
  <li>Model1</li>
  <li>Model2</li>
  <li>Model3</li>
  <li>Model4</li>
  <li>Model5</li>
  <li>Model6</li>
</ul>

Could any one provide some sample code to do that?
Thanks a lot

  • 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-11T21:18:41+00:00Added an answer on June 11, 2026 at 9:18 pm

    jQuery would be the easy way to do this, but if you’re forced to do it with pure Javascript, you’ll have something that looks like this:

    HTML:

    <textarea id="input" rows="5" cols="60">Brand: Brand1
        Model1 /Model2 /Model3 /Model4 /Model5 /Model6
        Brand: Brand2
        Model1 /Model2 /Model3 /Model4 /Model5 /Model6
    </textarea>
    
    <input id="convertButton" type="button" value="convert" />
    
    <div id="output"></div>
    

    Javascript:

    var convertButton = document.getElementById('convertButton');
    
    convertButton.onclick = function(){
        var input = document.getElementById('input');
        var output = document.getElementById('output');
    
        var lines = input.value.split( '\n' );
        var html = '';
        for( var i=0; i<lines.length; i++ ) {
            if( lines[i].indexOf('Brand')===0 ) {
                var brand = lines[i].split(':')[1];
                html += '<h3>' + brand + '</h3>';
            }
            if( lines[i].indexOf('/')!==-1 ) {
                var models = lines[i].split('/');
                html += '<ul><li>' + models.join('</li><li>') + '</li></ul>';
            }
        }
        output.innerHTML = html;
    };​
    

    Note that this solution doesn’t do a lot of error checking, and it would get pretty confused if you weren’t careful with your input, but it should give you a starting place to do what you want. See a live demo here: http://jsfiddle.net/GUQXf/4/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a relatively simple application which I need to make native Mac OSX
I cannot seem to make this simple code work: <script type=text/javascript> $(document).ready(function(){ $.getJSON('http://maps.google.com/maps/api/geocode/json?address=cebu&sensor=false&region=ph', function(results)
Im working on a simple html/javascript multiplication game, in which I have a multiplication
I need to make a long (>20 options) drop-down list in html, so I
I need to make simple javascript popups like the ones on alltop.com (when you
I made a simple ceasar cipher in javascript and I need to make it
I want to make simple classic inheritance with JavaScript. I just need sub classing
I need to make simple CRUD web app (i'll get paid for it), but
I need information about making installation packages for Linux. I want to make simple
I'm struggling with what should be somewhat simple. I need to make a regex

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.